diff options
| -rw-r--r-- | docs/superpowers/plans/2026-09-17-weather-widget.md | 5 | ||||
| -rw-r--r-- | lib/weather.lua | 5 |
2 files changed, 10 insertions, 0 deletions
diff --git a/docs/superpowers/plans/2026-09-17-weather-widget.md b/docs/superpowers/plans/2026-09-17-weather-widget.md index cf485ee..c394943 100644 --- a/docs/superpowers/plans/2026-09-17-weather-widget.md +++ b/docs/superpowers/plans/2026-09-17-weather-widget.md @@ -431,6 +431,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 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 |
