3 . $_EXEC/cgilite/cgilite.sh
4 . $_EXEC/cgilite/storage.sh
7 _(){ printf %s\\n "$*"; }
8 [ "${LANGUAGE}" -a -r "${_EXEC}/l10n/${LANGUAGE}.sh" ] && . "${_EXEC}/l10n/${LANGUAGE}.sh"
10 start_date= start_time= end_date= end_time=
11 rec_freq= rec_int= error_msg= rec_end=
13 start= end= nstart= nend=
15 while [ $# -gt 0 ]; do case $1 in
16 --from|from|--start|start)
17 if isdate "$2" && istime "$3" ; then
18 start_date="$(isdate "$2" )" start_time="$(istime "$3")"
20 elif isdate "${2%% *}" && istime "${2#* }" ; then
21 start_date="$(isdate "${2%% *}" )" start_time="$(istime "${2#* }")"
23 elif isdate "$2" ; then
24 start_date="$(isdate "$2")" start_time="00:00"
27 error_msg="Event start should be \"YYYY-MM-DD\" or \"YYYY-MM-DD hh:mm\""
32 if isdate "$2" && istime "$3"; then
33 end_date="$(isdate "$2")" end_time="$(istime "$3")"
35 elif isdate "${2%% *}" && istime "${2#* }"; then
36 end_date="$(isdate "${2%% *}")" end_time="$(istime "${2#* }")"
38 elif isdate "$2"; then
39 end_date="$(isdate "$2")" end_time="23:59"
41 elif istime "$2"; then
42 end_time="$(istime "$2")"
45 error_msg="Event end should be \"YYYY-MM-DD\" or \"YYYY-MM-DD hh:mm\" or \"hh:mm\""
49 --repeat|--recur|--recurrence|--every|every)
50 if expr "$2" : '^[0-9]\+$' &&
51 expr "$3" : '^\(days\|nights\|weeks\|months\|years\|weekday\)$'; then
52 rec_freq="$2" rec_int="$3"
54 elif expr "$2" : '^[0-9]\+ \+\(days\|nights\|weeks\|months\|years\|weekday\)$'; then
55 rec_freq="${2%% *}" rec_int="${2##* }"
57 elif expr "$2" : '^\(day\|daily\|night\|nightly\|week\|weekly\|month\|monthly\|year\|yearly\|annually\)$'; then
58 rec_freq="1" rec_int="$2"
60 elif expr "$2" : '^last weekday$'; then
61 rec_freq="-1" rec_int="weekday"
63 elif expr "$2 $3" : '^last weekday$'; then
64 rec_freq="-1" rec_int="weekday"
66 elif expr "$2" : '^\(biweekly\|bimonthly\)$'; then
67 rec_freq="2" rec_int="$2"
70 error_msg="Recurrence should be \"N days|weeks|months|years\" or \"N|last weekday\""
76 rec_end="$(isdate "$2")"
79 error_msg="Recurrence end should be \"YYYY-MM-DD\""
90 if [ ! "$end_time" ]; then
94 if [ ! "$end_date" -a "$end_time" -a "$start_time" ]; then
95 if [ "$((${end_time%:*} * 60 + ${end_time#*:}))" -gt "$((${start_time%:*} * 60 + ${start_time#*:}))" ]; then
96 end_date="$start_date"
98 end_date="$(date -ud "@$(($(date -ud "$start_date" +%s) + 86400))" +%F)"
102 if [ ! "$start_date" ]; then
103 error_msg="Event needs start date, e.g. --start \"YYYY-MM-DD\""
106 if [ ! "$title" ]; then
107 error_msg="Event needs title, e.g. --title \"Event Name\""
110 if [ "$error_msg" ]; then
116 day|daily|days|night|nightly|nights)
118 week|weeks|weekly|biweekly)
120 month|monthly|months|bimonthly)
122 year|yearly|years|annually)
126 [ "$rec_end" ] && rec_end="$(date -ud "$rec_end" +%s)" \
128 if LOCK './#events'; then
129 sed -i "/^${_DATE} /!d" './#events'
130 evid="$(wc -l <'./#events' || printf 0)"
131 printf '%i %i %i %i %s %i %s %s\n' \
132 "$_DATE" "$(date -ud "$start_date $start_time" +%s)" "$(date -ud "$end_date $end_time" +%s)" \
133 "${rec_freq:-0}" "${rec_int:-\\}" "${rec_end:--1}" "$(STRING "${title}")" "$(STRING "${PATH_INFO}#event${evid}")" \
138 printf '<div class="macro event" id="#event%s"></div>' "${evid}"
141 # tzid="$(cat /etc/timezone || printf 'UTC')"
143 # cat >>"#events.ics" <<-EOF
146 # PRODID:ShellWiki Event Macro
148 # UID:$uid@$(HEADER Host)
149 # DTSTAMP:TZID=${tzid}:$(date -u +%Y%m%dT%H%M%S)
150 # DTSTART:TZID=${tzid}:$(date -u +%Y%m%dT%H%M%S -d "$start_date $start_time")
152 # RRULE:FREQ=$ec_freq;INTERVAL=$rec_int;UNTIL=$(date -u +%Y%m%dT000000Z -d "$rec_end")