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_showdate32
1 files changed, 28 insertions, 4 deletions
diff --git a/Functions/Calendar/calendar_showdate b/Functions/Calendar/calendar_showdate
index 69588da4f..a8985513c 100644
--- a/Functions/Calendar/calendar_showdate
+++ b/Functions/Calendar/calendar_showdate
@@ -8,15 +8,39 @@ integer optr replyset
 zstyle -s ':datetime:calendar_showdate:' date-format datefmt ||
   datefmt="%a %b %d %H:%M:%S %Z %Y"
 
-while [[ $argv[$OPTIND] != +* ]] && getopts "r" opt; do
-  case $opt in
-    (r)
+# Memo to myself: both + and - are documented as giving relative
+# times, so it's not a good idea to rewrite this to use getopts.
+# We need to detect the small number of options this can actually
+# handle.
+while [[ $1 = -r || $1 = -- || $1 = -f* ]]; do
+  case $1 in
+    (-r)
+    shift
     REPLY=0
     optr=1
     ;;
+
+    (-f*)
+    if [[ $1 = -f?* ]]; then
+      datefmt=$1[3,-1]
+      shift
+    else
+      shift
+      if [[ -z $1 || $1 != *%* ]]; then
+	print "$0: -f requires a date/time specification" >&2
+	return 1
+      fi
+      datefmt=$1
+      shift
+    fi
+    ;;
+
+    (--)
+    shift
+    break
+    ;;
   esac
 done
-shift $(( OPTIND - 1 ))
 
 (( optr )) || local REPLY