diff options
| author | Danilo M. <danix@danix.xyz> | 2026-09-17 09:03:39 +0200 |
|---|---|---|
| committer | Danilo M. <danix@danix.xyz> | 2026-09-17 09:03:39 +0200 |
| commit | 752b58b3992d1a9cfb51c891deb77007286415ee (patch) | |
| tree | f1f6e7bdfb33d4ee1cbf208b1a59b007ed469d01 /lib | |
| parent | a9aa2ac3907cb24beae1ada6e58c59e61d16ece6 (diff) | |
| download | conky-theme-udt-752b58b3992d1a9cfb51c891deb77007286415ee.tar.gz conky-theme-udt-752b58b3992d1a9cfb51c891deb77007286415ee.zip | |
feat: add cache staleness classification
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
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 |
