]> git.plutz.net Git - shellwiki/blobdiff - macros/calendar
bugfix: octal interpretation of events at 8am and 9am, suppress calender error when...
[shellwiki] / macros / calendar
index 3d013f2a6a2d6acb47c21bc196c1d1a5789f30a0..b56784cee6203720c75154f099b35e31b9ade50c 100755 (executable)
@@ -43,7 +43,7 @@ while [ $# -gt 0 ]; do case $1 in
     fi;;
 esac; done
 
-[ "$*" ] || set -- "*"
+[ "$*" ] || set -- "."
 [ "$depth" -ge 0 -o "$depth" -le 0 ] 2>&- || depth=0
 
 read DY DM DD <<-EOF
@@ -68,6 +68,7 @@ rrexpand() {
   local junk1 start end rrfreq rrint rrend evtitle evlink junk2
 
   while read -r junk1 start end rrfreq rrint rrend evtitle evlink junk2; do
+    [ ! "$start" ] && continue  # empty line
     [ "$rrend" -eq -1 ] && rrend=9999999999
 
     if [ "$start" -lt "$dend" ] &&
@@ -182,20 +183,40 @@ rrex_weekday() {
 
   nth=$(( ( $(date -ud @$start +%_d) - 1) / 7))
 
-  nend=$(( 0 * 604800 - (dstart - end) % (rrfreq * 604800) + dstart ))
+  nend=$(( 0 * 604800 - (dstart - end) % 604800 + dstart ))
   nstart=$(( start - end + nend))
 
   while [ "$nstart" -lt "$rrend" -a "$nstart" -lt "$dend" ]; do
     [ "$nstart" -ge "$start" -a "$nstart" -ge "$dstart" ] \
     && [ "$(( ( $(date -ud @$nstart +%_d) -1) / 7 ))" -eq "$nth" ] \
     && printf '%i      %i      %s      %s\n' "$nstart" "$nend" "$evtitle" "$evlink"
-    nstart="$((nstart + rrfreq * 7 * 86400))"
+    nstart="$((nstart + 7 * 86400))"
       nend="$((nstart - start + end))"
   done
 }
 
 rrex_lastweekday() {
-:
+  # helper for rrexpand: Nth last weekday of a month (e.g. 2nd last tuesday, etc.)
+  local nstart nend Y m d nth
+
+  read Y m d <<-EOF
+       $(date -ud @$start +"%Y %_m %_d")
+       EOF
+  nth=$(( ( $(numdays $Y $m) - d ) / 7))
+
+  nend=$(( 0 * 604800 - (dstart - end) % 604800 + dstart ))
+  nstart=$(( start - end + nend))
+
+  while [ "$nstart" -lt "$rrend" -a "$nstart" -lt "$dend" ]; do
+    read Y m d <<-EOF
+       $(date -ud @$nstart +"%Y %_m %_d")
+       EOF
+    [ "$nstart" -ge "$start" -a "$nstart" -ge "$dstart" ] \
+    && [ "$(( ( $(numdays $Y $m) - d ) / 7 ))" -eq "$nth" ] \
+    && printf '%i      %i      %s      %s\n' "$nstart" "$nend" "$evtitle" "$evlink"
+    nstart="$((nstart + 7 * 86400))"
+      nend="$((nstart - start + end))"
+  done
 }
 
 events="$(
@@ -254,7 +275,6 @@ cal_month() {
   dcnt=$((iday - idow * 86400 + ws * 86400))
    dow=$ws
   dcal="$(date -ud @"$dcnt" +%d)"
-
   events="$(
     printf %s\\n "$events" \
     | rrexpand "$dcnt" "$((dcnt + 42 * 86400))" \
@@ -271,7 +291,7 @@ cal_month() {
     printf '<td><label>%02i</label>' "$dcal"
 
     evlist="$(
-      printf %s\\n "$events" \
+      printf %s "${events}${events:+${BR}}" \
       | while read start end title link; do
         if [ "$((start / 86400))" -lt "$((dcnt / 86400))" -a "$end" -gt "$dcnt" ]; then
           printf '<li><a href="%s\#%s">%s</a></li>' \