Commit: 32f266967aa1ee89d4d800b5705f4c6069546abe Parent: 30873aaa11a7d305709dc9e81ca2f4d448e202b3 Author: Vi Grey Date: 2023-08-28 08:39 UTC Summary: Better solar time handling using Equation Of Time src/moon.go | 29 +++++++++++++++++++++++++---- src/redshift.go | 3 +++ src/solartime.go | 17 ++++++++++------- 3 files changed, 38 insertions(+), 11 deletions(-) diff --git a/src/moon.go b/src/moon.go index c2ce777..b43d030 100644 --- a/src/moon.go +++ b/src/moon.go @@ -8,10 +8,31 @@ import ( ) type Syzygy struct { - MoonIllumination float64 `json:"moonIllumination"` - MoonPhase float64 `json:"moonPhase"` - SunAngle float64 `json:"sunAngle"` - SunEarthPhase float64 `json:"sunEarthPhase"` + MoonIllumination float64 `json:"moonIllumination"` + MoonPhase float64 `json:"moonPhase"` + SunAngle float64 `json:"sunAngle"` + SunEarthPhase float64 `json:"sunEarthPhase"` + EarthGeoditicLocation SyzygyGeoditicLocation `json:"earthGeoditicLocation"` + SunECEF SyzygyECEF `json:"sunECEF"` + EarthECEF SyzygyECEF `json:"earthECEF"` + EquationOfTime SyzygyEquationOfTime `json:"equationOfTime"` + Time float64 `json:"time"` +} + +type SyzygyGeoditicLocation struct { + Latitude float64 `json:"latitude"` + Longitude float64 `json:"longitude"` +} + +type SyzygyECEF struct { + X float64 `json:"x"` + Y float64 `json:"y"` + Z float64 `json:"z"` +} + +type SyzygyEquationOfTime struct { + Eccentricity float64 `json:"eccentricity"` + Obliquity float64 `json:"obliquity"` } func getSyzygyData() (s Syzygy) { diff --git a/src/redshift.go b/src/redshift.go index b4321dc..b48cd34 100644 --- a/src/redshift.go +++ b/src/redshift.go @@ -6,10 +6,13 @@ import ( "strconv" ) +const () + var ( rsBrightnessDiff float64 = 1 - 0.55 rsGreenDiff float64 = 1 - 0.88 rsBlueDiff float64 = 1 - 0.76 + sunRadius float64 = 695700.0 ) func getRedshiftScalingFactor(s Syzygy) float64 { diff --git a/src/solartime.go b/src/solartime.go index 7940f2d..ebe72bb 100644 --- a/src/solartime.go +++ b/src/solartime.go @@ -2,15 +2,18 @@ package main import ( "fmt" - "math" + "time" ) func getSolarTime(sy Syzygy) (s string) { if configData.SolarTime.Enabled { - hour, hourFrac := math.Modf(math.Mod(sy.SunEarthPhase+180, 360) / 360 * 24) - secondsInHour := int(hourFrac * 3600) - minute := secondsInHour / 60 - second := secondsInHour % 60 + newTime := time.Unix(int64(sy.Time), 0).UTC().Add( + time.Duration((sy.EarthGeoditicLocation.Longitude*4+ + sy.EquationOfTime.Eccentricity+ + sy.EquationOfTime.Obliquity)*60) * time.Second) + hour := newTime.Hour() + minute := newTime.Minute() + second := newTime.Second() hourPadding := "" ampm := "" if configData.SolarTime.TwelveHourTime { @@ -19,7 +22,7 @@ func getSolarTime(sy Syzygy) (s string) { } else { ampm += "AM" } - hour = math.Mod(hour, 12) + hour %= 12 if hour == 0 { hour = 12 } @@ -28,7 +31,7 @@ func getSolarTime(sy Syzygy) (s string) { hourPadding = "0" } } - s = fmt.Sprintf("%s%d:%02d:%02d%s | ", hourPadding, int(hour), minute, second, ampm) + s = fmt.Sprintf("%s%d:%02d:%02d%s | ", hourPadding, hour, minute, second, ampm) } return }