4 if [ "$1" = "$2" ] || [ "$1" -eq "$2" ]; then
5 printf 'checked="checked"'
9 if [ "$1" = "$2" ] || [ "$1" -eq "$2" ]; then
10 printf 'selected="selected"'
16 # 1. (optional) Name of select box, default "date"
17 # 2. (optional) Month to display in format: YYYY-MM, default current month
18 # 3. (optional) Day to preselect in format: DD, default none
20 local input="${1:-date}" month="$2" selected="$3"
21 local dow dom days n=1 Y m d V w B
23 read Y m d V w B<<-EOF
24 $(date -d "${month}-01" +"%Y %m %d %V %w %B")
28 $(date +"%Y %m %d %V %w")
32 [ $V -lt 1 ] && V=$((V + 53))
37 days="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31";;
39 days="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30";;
40 02) if [ $(( Y / 400 )) = 0 ]; then
41 days="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29";
42 elif [ $(( Y / 100 )) = 0 ]; then
43 days="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28";
44 elif [ $(( Y / 4 )) = 0 ]; then
45 days="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29";
47 days="1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28";
51 printf '[table .calendar month=%s [thead
52 [tr .monthname [th colspan=8 . %s]]
53 [tr .weekday [th][th . %s][th . %s][th . %s][th . %s][th . %s][th . %s][th . %s]]
55 ' "$month" "$B $Y" Mo Di Mi Do Fr Sa So
57 dow=$(( (w - d + 35 + dom ) % 7))
58 [ $dow = 1 -o $dom = 1 ] && printf '[tr [th .weekno . %i]' $V
59 [ $dom = 1 ] && while [ $n -lt $(( ($dow + 6) % 7 + 1)) ]; do printf '[td ]'; n=$((n + 1)); done
60 date="$(printf "%04i-%02i-%02i" $Y $m $dom)"
61 printf '[td [input type=radio id="%s_%s" name="%s" value="%s" %s][label for="%s_%s" . %i]]' \
62 "$input" "$date" "$input" "$date" "$(checked $dom $selected)" "$input" "$date" "$dom"
63 [ $dow = 0 ] && printf ']\n'
64 [ $dow = 0 ] && V=$(( V % 53 + 1))
66 if [ $dow -le 6 ]; then
67 while [ $dow -le 6 ]; do printf '[td ]'; dow=$((dow + 1)) ; done