Commit: 30873aaa11a7d305709dc9e81ca2f4d448e202b3 Parent: 82c0e997702b895185ccf3447ec91b13773edbb2 Author: Vi Grey Date: 2023-08-23 00:41 UTC Summary: Fix solar time (only positive) config | 4 ++++ src/solartime.go | 13 ++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/config b/config index 4458d3a..5279f69 100644 --- a/config +++ b/config @@ -2,6 +2,10 @@ "weather-station": "KVGT", "latitude": 36.1881, "longitude": -115.1764, + "solar-time": { + "enabled": true, + "twelve-hour-time": true + }, "email": [ { "inbox-path": "/home/example-user/mail/email@example.com/INBOX/", diff --git a/src/solartime.go b/src/solartime.go index c1a5cb3..7940f2d 100644 --- a/src/solartime.go +++ b/src/solartime.go @@ -7,11 +7,10 @@ import ( func getSolarTime(sy Syzygy) (s string) { if configData.SolarTime.Enabled { - hourData := (math.Mod(sy.SunEarthPhase+360, 360) - 180) / 15 - hour, hourFrac := math.Modf(hourData) - seconds := int(hourFrac * 3600) - minute := seconds / 60 - second := seconds % 60 + hour, hourFrac := math.Modf(math.Mod(sy.SunEarthPhase+180, 360) / 360 * 24) + secondsInHour := int(hourFrac * 3600) + minute := secondsInHour / 60 + second := secondsInHour % 60 hourPadding := "" ampm := "" if configData.SolarTime.TwelveHourTime { @@ -20,6 +19,10 @@ func getSolarTime(sy Syzygy) (s string) { } else { ampm += "AM" } + hour = math.Mod(hour, 12) + if hour == 0 { + hour = 12 + } } else { if hour < 10 { hourPadding = "0"