From 5882000904d06e2a85e11807a67990aed86b1510 Mon Sep 17 00:00:00 2001 From: MarcinM Date: Wed, 31 Mar 2021 12:19:10 +0200 Subject: [PATCH] widget.cal: fix week numbers (#501) widget.cal: fix week numbers; closes #487 --- widget/cal.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/widget/cal.lua b/widget/cal.lua index fe5d343..7543684 100644 --- a/widget/cal.lua +++ b/widget/cal.lua @@ -38,7 +38,15 @@ local function factory(args) } function cal.get_week_number(m, st_day, x) - return string.format(cal.week_number_format, os.date("%V", m) + (x ~= 0 and floor((x + st_day) / 7) - 1 or 0)) + local date = os.date("*t", m) + + local week_step = (x ~= 0 and floor((x + st_day) / 7) - 1 or 0); + + local display_time = os.time { + year = date.year, month = date.month, day = date.day + 7 * week_step + } + + return string.format(cal.week_number_format, os.date("%V", display_time)) end function cal.sum_week_days(x, y) @@ -69,7 +77,7 @@ local function factory(args) cal.month, cal.year = d.month, d.year if cal.week_number ~= "none" then - local m = os.time { year = year or current_year, month = month and month or current_month, day = 0 } + local m = os.time { year = year or current_year, month = month and month or current_month, day = 1 } local head_prepend = string.rep(" ", tostring(string.format(cal.week_number_format, 0)):len()) if cal.week_number == "left" then