Skip to content

Commit

Permalink
fix cal align for short day names
Browse files Browse the repository at this point in the history
If the day names do not consist of three characters, the alignment is off
(see lcpz#522)
  • Loading branch information
Florian Baumgärtner committed Oct 18, 2022
1 parent c489aa6 commit ef66382
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion widget/cal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ local function factory(args)
return (x + y) % 7
end

function cal.get_dayname(day_num)
--- Expand day name to three chars for alignment
local day_name = os.date("%a", os.time { year=2006, month=1, day=day_num+cal.week_start })
if string.len(day_name) == 2 then
day_name = " "..day_name
end
return day_name
end

function cal.build(month, year)
local current_month, current_year = tonumber(os.date("%m")), tonumber(os.date("%Y"))
local is_current_month = (not month or not year) or (month == current_month and year == current_year)
Expand All @@ -61,7 +70,7 @@ local function factory(args)
local d = os.date("*t", t)
local mth_days, st_day, this_month = d.day, (d.wday-d.day-cal.week_start+1)%7, os.date("%B %Y", t)
local notifytable = { [1] = string.format("%s%s\n", string.rep(" ", floor((28 - this_month:len())/2)), markup.bold(this_month)) }
for x = 0,6 do notifytable[#notifytable+1] = os.date("%a", os.time { year=2006, month=1, day=x+cal.week_start }):sub(1, utf8.offset(1, 3)) .. " " end
for x = 0,6 do notifytable[#notifytable+1] = cal.get_dayname(x):sub(1, utf8.offset(1, 3)) .. " " end
notifytable[#notifytable] = string.format("%s\n%s", notifytable[#notifytable]:sub(1, -2), string.rep(" ", st_day*4))
local strx
for x = 1,mth_days do
Expand Down

0 comments on commit ef66382

Please sign in to comment.