Open
Description
In time/zoneinfo_js.go
the local timezone is determined by the UTC offset returned by the JS call:
(new Date()).getTimezoneOffset()
However UTC offset != timezone
and this behaviour causes issues with displaying 'daylight savings' times. This behaviour is unexpected and undocumented and I would expect that time.Local is set to the JS environment's timezone (where available) instead of the current UTC offset.
The timezone can be determined in JS with the Internationalization API:
Intl.DateTimeFormat().resolvedOptions().timeZone
As long as the tzdata package has been imported/embedded and the its init function runs first, adding the following code to the beginning of initLocal should (in theory) fix this issue.
func initLocal() {
if intl := js.Global().Get("Intl"); !intl.IsUndefined() {
var err error
tz := js.Global().Get("Intl").Call("DateTimeFormat").Call("resolvedOptions").Get("timeZone").String()
Local, err = LoadLocation(tz)
if err == nil {
return
}
}
...