about summary refs log tree commit diff
path: root/Functions/Calendar/calendar_showdate
blob: b35a0a91ff3a3b4332ec45d52f79cf008929a491 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
emulate -L zsh
setopt extendedglob

local optm datefmt
integer optr replyset

zstyle -s ':datetime:calendar_showdate:' date-format datefmt ||
  datefmt="%a %b %d %H:%M:%S %Z %Y"

if [[ $1 = -r ]]; then
  shift
  REPLY=0
  optr=1
else
  local REPLY
fi

if (( ! $# )); then
  print "Usage: $0 datespec [ ... ]" >&2
  return 1
fi

while (( $# )); do
  optm=
  if [[ $1 = [-+]* ]]; then
    # relative
    [[ $1 = -* ]] && optm=-m
    1=${1[2,-1]}
    # if this is the first argument, use current time
    # don't make assumptions about type of reply in case global
    if (( ! replyset )); then
      REPLY=$EPOCHSECONDS
      replyset=1
    fi
  fi

  if (( replyset )); then
    calendar_scandate $optm -R $REPLY -aA $1 || return 1
    replyset=1
  else
    calendar_scandate -aA $1 || return 1
  fi

  shift
done

(( optr )) && return
strftime $datefmt $REPLY