about summary refs log tree commit diff
path: root/Functions/Calendar/calendar_showdate
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2007-01-31 16:53:31 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2007-01-31 16:53:31 +0000
commit483810a525b138f91dcb11f5864817a6e9ba6699 (patch)
tree9ba7a31bd5566d01148c7db20fadf76476148323 /Functions/Calendar/calendar_showdate
parenta1476c1ee262e2b75bf12ade0e1225158e835453 (diff)
downloadzsh-483810a525b138f91dcb11f5864817a6e9ba6699.tar.gz
zsh-483810a525b138f91dcb11f5864817a6e9ba6699.tar.xz
zsh-483810a525b138f91dcb11f5864817a6e9ba6699.zip
23142: calendar enhancements: relative times, recurring events
Diffstat (limited to 'Functions/Calendar/calendar_showdate')
-rw-r--r--Functions/Calendar/calendar_showdate48
1 files changed, 48 insertions, 0 deletions
diff --git a/Functions/Calendar/calendar_showdate b/Functions/Calendar/calendar_showdate
new file mode 100644
index 000000000..b35a0a91f
--- /dev/null
+++ b/Functions/Calendar/calendar_showdate
@@ -0,0 +1,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