aboutsummaryrefslogtreecommitdiffstats
path: root/lib/weather.lua
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-17 08:58:26 +0200
committerDanilo M. <danix@danix.xyz>2026-09-17 08:58:26 +0200
commite9dd31b04324d9a95acf6561a4b6ebcee9d3b8c0 (patch)
treebf7e7bd05e5cbbbae71a333fa299e8f9f73f7ab0 /lib/weather.lua
parent2b499067d07328e775547059212bf3737cfcfdd4 (diff)
downloadconky-theme-udt-e9dd31b04324d9a95acf6561a4b6ebcee9d3b8c0.tar.gz
conky-theme-udt-e9dd31b04324d9a95acf6561a4b6ebcee9d3b8c0.zip
docs: note that sun_t passes a NaN timestamp through
NaN is a number, so the type guard admits it, and every comparison against NaN is false, so neither clamp catches it and the function returns NaN. Left unguarded on purpose. No caller can produce it: parse() matches %d+ for the sun times and `now` is os.time(). If one ever did, Cairo ignores a NaN coordinate, so the arc would lose its dot rather than the dashboard going blank. A ponytail: comment names the ceiling and where the guard would go. Found while probing the committed code, not by the tests, which do not cover NaN. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'lib/weather.lua')
-rw-r--r--lib/weather.lua5
1 files changed, 5 insertions, 0 deletions
diff --git a/lib/weather.lua b/lib/weather.lua
index f8c7517..84f355a 100644
--- a/lib/weather.lua
+++ b/lib/weather.lua
@@ -124,6 +124,11 @@ function M.sun_t(now, sunrise, sunset)
or type(sunset) ~= 'number' then return nil end
local span = sunset - sunrise
if span <= 0 then return 0 end -- polar day/night or bad data: no division
+ -- ponytail: a NaN timestamp slips through, since NaN is a number and every
+ -- comparison against it is false, so both clamps below fall through and this
+ -- returns NaN. Unreachable today: parse() matches %d+ for the sun times and
+ -- `now` is os.time(). Cairo ignores a NaN coordinate, so the cost would be a
+ -- missing dot, not a crash. Guard it here if a caller ever computes `now`.
local t = (now - sunrise) / span
if t < 0 then return 0 elseif t > 1 then return 1 end
return t