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