]> git.plutz.net Git - shellwiki/blobdiff - macros/calendar
nth-last-weekday recurrence
[shellwiki] / macros / calendar
index 3d013f2a6a2d6acb47c21bc196c1d1a5789f30a0..5a486756537b452d6e53143dff2223bbef2215c6 100755 (executable)
@@ -182,20 +182,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="$(