aboutsummaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-09-17 08:57:27 +0200
committerDanilo M. <danix@danix.xyz>2026-09-17 08:57:27 +0200
commit2b499067d07328e775547059212bf3737cfcfdd4 (patch)
tree4971a888f526373d2014a34a835f140a3ab4da60 /lib
parent17692349e6b6ce3f6083b5d565dda9f3ca7dba22 (diff)
downloadconky-theme-udt-2b499067d07328e775547059212bf3737cfcfdd4.tar.gz
conky-theme-udt-2b499067d07328e775547059212bf3737cfcfdd4.zip
feat: add sun position along the daylight arc
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/weather.lua24
1 files changed, 24 insertions, 0 deletions
diff --git a/lib/weather.lua b/lib/weather.lua
index ac1f4cf..f8c7517 100644
--- a/lib/weather.lua
+++ b/lib/weather.lua
@@ -113,4 +113,28 @@ function M.arrow(deg)
return ARROWS[i + 1]
end
+-- Fraction of daylight elapsed, clamped to 0..1.
+--
+-- OWM returns TODAY's sunrise and sunset, so before dawn this is negative and
+-- after dusk it is over 1. Clamping parks the dot at the corresponding end of
+-- the arc, which is the cheap correct-enough behaviour; multi-day astronomy
+-- buys nothing for a dot on a curve.
+function M.sun_t(now, sunrise, sunset)
+ if type(now) ~= 'number' or type(sunrise) ~= 'number'
+ 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
+ local t = (now - sunrise) / span
+ if t < 0 then return 0 elseif t > 1 then return 1 end
+ return t
+end
+
+-- Whether the sun is up. Inclusive at both ends, matching the polybar script's
+-- comparison, so the instant of sunrise draws the day face.
+function M.is_day(now, sunrise, sunset)
+ if type(now) ~= 'number' or type(sunrise) ~= 'number'
+ or type(sunset) ~= 'number' then return true end
+ return now >= sunrise and now <= sunset
+end
+
return M