Skip to content
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: Now doesn't update when timezone is changed #46417

Closed
tommyblue opened this issue May 27, 2021 · 3 comments
Closed

time: Now doesn't update when timezone is changed #46417

tommyblue opened this issue May 27, 2021 · 3 comments
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@tommyblue
Copy link

tommyblue commented May 27, 2021

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

$ go version
go version go1.16.4 linux/amd64

Does this issue reproduce with the latest release?

it's the latest release

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

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN="/home/tommyblue/src/go/bin"
GOCACHE="/home/tommyblue/.cache/go-build"
GOENV="/home/tommyblue/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/tommyblue/src/go/pkg/mod"
GOOS="linux"
GOPATH="/home/tommyblue/src/go"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/home/tommyblue/dev/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/home/tommyblue/dev/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16.4"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build2846216330=/tmp/go-build -gno-record-gcc-switches"

What did you do?

Changing the system timezone with timedatectl set-timezone <tz> doesn't change the output of time.Now() until the go program is restarted.

To reproduce, run a simple program that prints time.Now(), like the one below, and change the system timezone while it is running.
The output doesn't get updated with the new time/timezone until the program is restarted


import (
        "fmt"
        "time"
)

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

What did you expect to see?

The datetime should change to the new timezone

What did you see instead?

The datetime remains the same until the program is restarted

@mknyszek mknyszek changed the title time.Now() doesn't update when timezone is changed time: Now doesn't update when timezone is changed May 27, 2021
@mknyszek mknyszek added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label May 27, 2021
@mknyszek mknyszek added this to the Backlog milestone May 27, 2021
@mknyszek
Copy link
Contributor

Interesting. Are other applications able to handle this on the fly? I genuinely don't know.

CC @rsc via https://dev.golang.org/owners

@tommyblue
Copy link
Author

Probably changing time zone is something that doesn't happen often, but I'm building a long-living app for an embedded system and users can change the timezone through the app itself (generally at first setup)

@seankhliao
Copy link
Member

Duplicate of #28020

@seankhliao seankhliao marked this as a duplicate of #28020 May 27, 2021
@golang golang locked and limited conversation to collaborators May 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants