fails to get proper sunrise / sunset time in certain timezones, with UTC input
Thanks for creating awesome linux desktop tools!
I'm located in Japan, where JST (UTC +9) timezone is used. I've noticed that darkman does not trigger mode switch at sunrise, while it does at sunset.
my environment:
| key | val |
|---|---|
| distro | Arch Linux |
| installation |
darkman on AUR |
| running method | systemd |
| location provider | geoclue |
from the systemd logs around sunrise time, it appears that Next sunrise is set to past time, which causes timer value to be negative and the mode is not switched.
# all timestamps converted to UTC
Jul 22 19:43:09 Archaxibami darkman[1599]: boottimer.go:62: Got signal: alarm clock
Jul 22 19:43:09 Archaxibami darkman[1599]: scheduler.go:55: Sunrise comes first; so it's night time.
Jul 22 19:43:09 Archaxibami darkman[1599]: main.go:34: Mode should now be: dark mode.
Jul 22 19:43:09 Archaxibami darkman[1599]: main.go:36: No transition necessary
Jul 22 19:43:09 Archaxibami darkman[1599]: scheduler.go:142: Next sunrise: 2022-07-22 19:43:04.193144736 +0000 UTC
Jul 22 19:43:09 Archaxibami darkman[1599]: scheduler.go:143: Next sundown: 2022-07-23 09:52:29.068875398 +0000 UTC
Jul 22 19:43:09 Archaxibami darkman[1599]: scheduler.go:148: Will set an alarm for sunrise
Jul 22 19:43:09 Archaxibami darkman[1599]: boottimer.go:39: Setting timer for -5.-225175869 seconds.
so I tested astral module used in scheduler.go with below code, with JST & UTC inputs.
package main
import (
"flag"
"fmt"
"github.com/sj14/astral"
"time"
)
func main() {
var (
utcstr = flag.String("utc", time.Now().Format(time.RFC3339), "UTC input")
jststr = flag.String("jst", time.Now().Format(time.RFC3339), "JST input")
)
flag.Parse()
utc, err := time.Parse(time.RFC3339, *utcstr)
jst, err := time.Parse(time.RFC3339, *jststr)
obs := astral.Observer{
Latitude: 35.4,
Longitude: 139.6,
Elevation: 0,
}
utc_sunrise, err := astral.Sunrise(obs, utc)
utc_sundown, err := astral.Sunset(obs, utc)
jst_sunrise, err := astral.Sunrise(obs, jst)
jst_sundown, err := astral.Sunset(obs, jst)
fmt.Printf("UTC Input: %s\n", utcstr)
fmt.Printf("JST Input: %s\n\n", jststr)
fmt.Printf("With UTC:\n")
fmt.Printf("\tSunrise: %v\n", utc_sunrise)
fmt.Printf("\tSundown: %v\n", utc_sundown)
fmt.Printf("With JST:\n")
fmt.Printf("\tSunrise: %v\n\t(= %v)\n", jst_sunrise, jst_sunrise.UTC())
fmt.Printf("\tSundown: %v\n\t(= %v)\n", jst_sundown, jst_sundown.UTC())
if err != nil {
return
}
}
go run main.go -utc "2022-07-22T19:43:04+00:00" -jst "2022-07-23T04:43:04+09:00"
Output:
UTC Input: 2022-07-22T19:43:04+00:00
JST Input: 2022-07-23T04:43:04+09:00
With UTC:
Sunrise: 2022-07-21 19:42:37.703544036 +0000 +0000
Sundown: 2022-07-22 09:53:07.288127707 +0000 +0000
With JST:
Sunrise: 2022-07-23 04:42:37.703544036 +0900 JST
(= 2022-07-22 19:42:37.703544036 +0000 UTC)
Sundown: 2022-07-23 18:53:07.288127707 +0900 JST
(= 2022-07-23 09:53:07.288127707 +0000 UTC)
Apparently, when input is UTC time, both astral.Sunrise() and astral.Sunset() return sunset / sunrise time with yesterday's date in Japan.
I'm new to this kind of timer tool, but does using local time instead of UTC in darkman cause problems? Or is there any other better solution?
Edited by haxibami