From 752b58b3992d1a9cfb51c891deb77007286415ee Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Thu, 17 Sep 2026 09:03:39 +0200 Subject: feat: add cache staleness classification Co-Authored-By: Claude Opus 5 --- lib/weather.lua | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'lib') diff --git a/lib/weather.lua b/lib/weather.lua index d36bcf5..b1fda4d 100644 --- a/lib/weather.lua +++ b/lib/weather.lua @@ -186,4 +186,21 @@ function M.parse(src) return w end +-- Three missed fetches at the 15-minute interval. +M.STALE_AFTER = 45 * 60 + +function M.is_stale(dt, now) + if type(dt) ~= 'number' then return true end + return (now - dt) > M.STALE_AFTER +end + +-- Short age for the marker beside the city: "12m", "3h", "2d". +function M.age_str(dt, now) + if type(dt) ~= 'number' then return '?' end + local s = now - dt + if s < 3600 then return math.floor(s / 60) .. 'm' end + if s < 86400 then return math.floor(s / 3600) .. 'h' end + return math.floor(s / 86400) .. 'd' +end + return M -- cgit v1.2.3