From 1acc7a24dadd5d9c930a43e5f8a6e68f067f11f8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Paul=20H=C3=A4nsch?= Date: Fri, 23 Jul 2021 15:41:03 +0200 Subject: [PATCH] avoid accidental octals in math expression, fix week number in january after 52 week years --- widgets.sh | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/widgets.sh b/widgets.sh index 472318d..5e7132e 100755 --- a/widgets.sh +++ b/widgets.sh @@ -31,7 +31,7 @@ w_month() { local dow dom days n=1 Y m d V w B if [ $month ]; then read Y m d V w B<<-EOF - $(date -d "${month}-01" +"%Y %m %d %V %w %B") + $(date -d "${month}-01" +"%_Y %_m %_d %_V %w %B") EOF else read Y m d V w <<-EOF @@ -43,11 +43,11 @@ w_month() { fi case $m in - 0[13578]|10|12) + [13578]|10|12) 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";; - 0[469]|11) + [469]|11) 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";; - 02) if [ $(( Y / 400 )) = 0 ]; then + 2) if [ $(( Y / 400 )) = 0 ]; then 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"; elif [ $(( Y / 100 )) = 0 ]; then 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"; @@ -82,10 +82,13 @@ w_month() { "$input" "$date" "$input" "$date" "$(checked $dom $selected)" "$input" "$date" "$dom" ;; esac - [ $dow = 0 ] && printf ']\n' - [ $dow = 0 ] && V=$(( V % 53 + 1)) + if [ $dow = 0 ]; then + printf ']\n' + V=$((V + 1)) + [ $m = 1 -a $V -ge 53 ] && V=1 + fi done - if [ $dow -le 6 ]; then + if [ $dow -gt 0 ]; then while [ $dow -le 6 ]; do printf '[td ]'; dow=$((dow + 1)) ; done printf ']\n' fi -- 2.39.2