From 48fa63ff5d0e12edf86db7f01def635aa0aaa9fb Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Sun, 18 Oct 2026 15:29:35 +0200 Subject: fix(calendar): mark events past this week on the month grid The sampler asked khal for 8 days only, so the grid never coloured an event later in the month. Sample through the month's end instead, and cut the event table back to the coming week with calendar_upcoming(). Co-Authored-By: Claude Opus 5.5 --- lib/data.lua | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'lib') diff --git a/lib/data.lua b/lib/data.lua index 1b4c64f..818bbf1 100644 --- a/lib/data.lua +++ b/lib/data.lua @@ -131,6 +131,21 @@ function M.calendar_month_days(events, year, month) return out end +-- The events falling within `days` days of `today` ({ y, m, d }), today +-- included. The cache spans the rest of the month so the grid can mark it, +-- while the event table under the grid stays a week's view. +function M.calendar_upcoming(events, today, days) + local out = {} + if type(events) ~= 'table' or type(today) ~= 'table' then return out end + local t0 = os.time({ year = today[1], month = today[2], day = today[3], + hour = 12 }) + for _, e in ipairs(events) do + local t = os.time({ year = e.y, month = e.m, day = e.d, hour = 12 }) + if (t - t0) / 86400 < days then out[#out + 1] = e end + end + return out +end + -- Days in a month, and the weekday its 1st falls on. -- -- os.time/os.date rather than a leap-year rule: the C library already knows, -- cgit v1.2.3