New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

time: notice system timezone changes #28020

Open
tv42 opened this Issue Oct 4, 2018 · 2 comments

Comments

Projects
None yet
2 participants
@tv42
Copy link

tv42 commented Oct 4, 2018

What version of Go are you using (go version)?

go version go1.11.1 linux/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

package main

import (
	"fmt"
	"time"
)

func main() {
	for {
		time.Sleep(1 * time.Second)
		fmt.Println(time.Now())
	}
}

in one terminal:

$ go run time.go

in another (note, this changes your computer's timezone):

$ timedatectl set-timezone America/Denver
$ date
Thu Oct  4 12:48:50 MDT 2018
$ timedatectl set-timezone America/Los_Angeles
$ date
Thu Oct  4 11:48:56 PDT 2018
$ 

What did you expect to see?

Go process seeing that the current time changes between MDT and PDT, time displayed changing by an hour.

As far as I can tell, there's not even a way to tell package time to re-initialize its idea of local time, even if my app somehow (in a platform-specific way) realized that it was necessary.

This hurts long-running end-user apps when users travel. Think of e.g. a desktop clock.

What did you see instead?

2018-10-04 12:48:48.12727581 -0600 MDT m=+1.000767878
2018-10-04 12:48:49.127890815 -0600 MDT m=+2.001383092
2018-10-04 12:48:50.128187914 -0600 MDT m=+3.001680261
2018-10-04 12:48:51.128403029 -0600 MDT m=+4.001895306
2018-10-04 12:48:52.128632471 -0600 MDT m=+5.002124678
2018-10-04 12:48:53.128842855 -0600 MDT m=+6.002335551
2018-10-04 12:48:54.129075736 -0600 MDT m=+7.002568154
2018-10-04 12:48:55.129282227 -0600 MDT m=+8.002787356
2018-10-04 12:48:56.129528956 -0600 MDT m=+9.003021303
2018-10-04 12:48:57.129734907 -0600 MDT m=+10.003227044
2018-10-04 12:48:58.129960422 -0600 MDT m=+11.003452839
2018-10-04 12:48:59.130145298 -0600 MDT m=+12.003637576

@ianlancetaylor ianlancetaylor changed the title time: Follow timezone changes time: notice system timezone changes Oct 4, 2018

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Oct 4, 2018

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

ianlancetaylor commented Oct 4, 2018

What does the C library do?

@tv42

This comment has been minimized.

Copy link

tv42 commented Oct 5, 2018

I haven't (yet) written C to test it, but my current understanding is:

localtime(3) and friends cache values on first use. tzset(3) reloads the cache. So libc enables one to easily handle this in the app; Go doesn't. (And, IMHO, Go should aim higher than libc.)

glibc argument for not stat(2)ing /etc/localtime on every localtime(3) call was performance. inotify and friends might change that equation.

Random discussion found:
https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=48184
https://sourceware.org/bugzilla/show_bug.cgi?id=154

soumya92 added a commit to soumya92/barista that referenced this issue Dec 7, 2018

Track machine time zone changes in clock.Local
Go pins time.Local at the start of the binary (golang/go#28020), but because the bar can run for days on end even as the machine moves around the world, we need to track the machine timezone for local clock modules.
This changes clock.Module to handle a nil timezone as "true" machine-local time zone, updating the output any time the timezone changes locally.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment