From: Paul Hänsch Date: Thu, 1 Feb 2024 17:17:58 +0000 (+0100) Subject: weekday recurrence (e.g. 2nd tuesday of a month, etc.) X-Git-Url: https://git.plutz.net/?p=shellwiki;a=commitdiff_plain;h=621ce9f6f8d1371840630721f66a8f9c9ed895af weekday recurrence (e.g. 2nd tuesday of a month, etc.) --- diff --git a/macros/calendar b/macros/calendar index e2fa8aa..3d013f2 100755 --- a/macros/calendar +++ b/macros/calendar @@ -77,6 +77,10 @@ rrexpand() { week) rrex_week;; month) rrex_month;; year) rrex_year;; + weekday) + [ "$rrfreq" -ge 0 ] && rrex_weekday \ + || rrex_lastweekday + ;; *): printf '%i %i %s %s\n' "$start" "$end" "$evtitle" "$evlink" ;; @@ -172,6 +176,28 @@ rrex_year() { done } +rrex_weekday() { + # helper for rrexpand: Nth weekday of a month (e.g. 2nd tuesday, etc.) + local nstart nend + + nth=$(( ( $(date -ud @$start +%_d) - 1) / 7)) + + nend=$(( 0 * 604800 - (dstart - end) % (rrfreq * 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))" + nend="$((nstart - start + end))" + done +} + +rrex_lastweekday() { +: +} + events="$( for dir in "$@"; do page_glob "$dir" "$depth" @@ -277,5 +303,5 @@ cal_month() { printf '' } -%rem cal_list +# cal_list cal_month