about summary refs log tree commit diff
path: root/Functions/Calendar/calendar_showdate
diff options
context:
space:
mode:
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