diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/data.lua | 15 |
1 files changed, 15 insertions, 0 deletions
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, |
