From b784aad67a5306930659704613e69bafdacf9f6e Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Tue, 19 Feb 2008 14:59:52 +0000 Subject: 24572: add style reformat-date to calendar --- ChangeLog | 5 +++++ Doc/Zsh/calsys.yo | 12 ++++++++++++ Functions/Calendar/calendar_add | 22 ++++++++++++++++------ 3 files changed, 33 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 9d7134884..bf44bb3ca 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-02-19 Peter Stephenson + + * 24572: Doc/Zsh/calsys.yo, Functions/Calendar/calendar_add: + add style reformate-date. + 2008-02-17 Barton E. Schaefer * users/12600: Src/builtin.c: reorder handling of -s/-d/-t options diff --git a/Doc/Zsh/calsys.yo b/Doc/Zsh/calsys.yo index 6e38bb0bc..8758b1189 100644 --- a/Doc/Zsh/calsys.yo +++ b/Doc/Zsh/calsys.yo @@ -440,6 +440,10 @@ option tt(-L) indicates that tt(calendar_add) does not need to lock the calendar file as it is already locked. These options will not usually be needed by users. +If the style tt(reformat-date) is true, the date and time of the +new entry will be rewritten into the standard date format: see +the descriptions of this style and the style tt(date-format). + The function can use a unique identifier stored with each event to ensure that updates to existing events are treated correctly. The entry should contain the word tt(UID), followed by whitespace, followed by @@ -624,6 +628,14 @@ The default is the calendar file location with the suffix tt(.done). The style may be set to an empty string in which case a "done" file will not be maintained. ) +kindex(reformat-date) +item(tt(reformat-date))( +Boolean, used by tt(calendar_add). If it is true, the date and time +of new entries added to the calendar will be reformatted to the format +given by the style tt(date-format) or its default. Only the date and +time of the event itself is reformatted; any subsidiary dates and times +such as those associated with repeat and warning times are left alone. +) kindex(show-prog) item(tt(show-prog))( The programme run by tt(calendar) for showing events. It will diff --git a/Functions/Calendar/calendar_add b/Functions/Calendar/calendar_add index c24556585..592c9d671 100644 --- a/Functions/Calendar/calendar_add +++ b/Functions/Calendar/calendar_add @@ -8,6 +8,8 @@ emulate -L zsh setopt extendedglob +local context=":datetime:calendar_add:" + local calendar newfile REPLY lastline opt local -a calendar_entries lockfiles reply integer my_date done rstat nolock nobackup new_recurring old_recurring @@ -33,17 +35,25 @@ done shift $(( OPTIND - 1 )) # Read the calendar file from the calendar-file style -zstyle -s ':datetime:calendar_add:' calendar-file calendar || +zstyle -s $context calendar-file calendar || calendar=~/calendar newfile=$calendar.new.$HOST.$$ -if ! calendar_parse "$*"; then +local addline="$*" +if ! calendar_parse $addline; then print "$0: failed to parse date/time" >&2 return 1 fi parse_new=("${(@kv)reply}") (( my_date = $parse_new[time] )) [[ -n $parse_new[rpttime] ]] && (( new_recurring = 1 )) +if zstyle -t $context reformat-date; then + local datefmt + zstyle -s $context date-format datefmt || + datefmt="%a %b %d %H:%M:%S %Z %Y" + strftime -s REPLY $datefmt $parse_new[time] + addline="$REPLY $parse_new[text1]" +fi # $calendar doesn't necessarily exist yet. @@ -53,7 +63,7 @@ local my_uid their_uid # Match a UID, a unique identifier for the entry inherited from # text/calendar format. local uidpat='(|*[[:space:]])UID[[:space:]]##(#b)([[:xdigit:]]##)(|[[:space:]]*)' -if [[ "$*" = ${~uidpat} ]]; then +if [[ $addline = ${~uidpat} ]]; then my_uid=${(U)match[1]} fi @@ -82,7 +92,7 @@ fi calendar_parse $line || continue parse_old=("${(@kv)reply}") if (( ! done && ${parse_old[time]} > my_date )); then - print -r -- "$*" + print -r -- $addline (( done = 1 )) fi if [[ -n $parse_old[rpttime] ]]; then @@ -119,13 +129,13 @@ fi fi fi fi - if [[ $REPLY -eq $my_date && $line = "$*" ]]; then + if [[ $parse_old[time] -eq $my_date && $line = $addline ]]; then (( done )) && continue # paranoia: shouldn't happen (( done = 1 )) fi print -r -- $line done - (( done )) || print -r -- "$*" + (( done )) || print -r -- $addline } >$newfile if (( ! nobackup )); then if ! mv $calendar $calendar.old; then -- cgit 1.4.1