fi;;
esac; done
-[ "$*" ] || set -- "*"
+[ "$*" ] || set -- "."
[ "$depth" -ge 0 -o "$depth" -le 0 ] 2>&- || depth=0
read DY DM DD <<-EOF
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" ] &&
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"
;;
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) % 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 + 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="$(
for dir in "$@"; do
page_glob "$dir" "$depth"
dcnt=$((iday - idow * 86400 + ws * 86400))
dow=$ws
dcal="$(date -ud @"$dcnt" +%d)"
-
events="$(
printf %s\\n "$events" \
| rrexpand "$dcnt" "$((dcnt + 42 * 86400))" \
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>' \
"$(UNSTRING "${link#*#}" |URL)" \
"$(UNSTRING "$title" |HTML)"
elif [ "$((start / 86400))" -eq "$((dcnt / 86400))" ]; then
- printf '<li>%s - <a href="%s\#%s">%s</a></li>' \
+ printf '<li>%s - <a href="%s#%s">%s</a></li>' \
"$(date -ud @"$start" +%H:%M)" \
"$(UNSTRING "${link%%#*}" |URL)" \
"$(UNSTRING "${link#*#}" |URL)" \
printf '</tbody></table>'
}
-%rem cal_list
+# cal_list
cal_month