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: inconsistent handling of CEST time zone #34913

Closed
infomaniac opened this issue Oct 15, 2019 · 11 comments
Closed

time: inconsistent handling of CEST time zone #34913

infomaniac opened this issue Oct 15, 2019 · 11 comments
Milestone

Comments

@infomaniac
Copy link

@infomaniac infomaniac commented Oct 15, 2019

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

Mac:
$ go version go1.13 darwin/amd64
Docker/Linux (image golang:1.13.1):
$ go version go1.13.1 linux/amd64

Does this issue reproduce with the latest release?

Yes

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

MAC go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/myuser/Library/Caches/go-build"
GOENV="/Users/myuser/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/myuser/myproject"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/Cellar/go/1.13/libexec"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.13/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD=""
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 -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/zx/tn2qh7xs46d352mn58mr2dcm0000gn/T/go-build417813244=/tmp/go-build -gno-record-gcc-switches -fno-common"
Docker/Linux go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/root/.cache/go-build"
GOENV="/root/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/drone/src"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
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-build206921703=/tmp/go-build -gno-record-gcc-switches"

What did you do?

https://play.golang.org/p/mgNY9kKCUw6

pt, err := time.Parse("20060102 150405 MST", "20190906 062023 CEST")
expected := time.Date(2019, 9, 06, 04, 20, 23, 0, time.UTC)
diff := pt.Sub(expected)

The same absolute time created with different timezones should have 0 difference.
This works on Mac, but not on Docker/Linux.

What did you expect to see?

0s duration as difference when subtracting the times.

What did you see instead?

On go1.13 darwin/amd64 it works as expected, difference is 0s duration
On go1.13.1 linux/amd64 the difference is 2h0m0s duration

@bcmills
Copy link
Member

@bcmills bcmills commented Oct 15, 2019

CEST is not an IANA time zone name.

(CET is, but it's deprecated; CEST seems to exist on Windows, but the script to update those abbreviations apparently hasn't been run since last June.)

So I see (at least) two issues here:

  1. The documentation for time.Location and time.Equal probably should not refer to CEST, since that zone does not exist in the database uniformly.

  2. time.Parse should report a non-nil error if the time zone is unrecognized.

CC @ianlancetaylor

@bcmills bcmills changed the title time.Time.Sub(time.Time) ignores timezone on Linux, works on Mac time: inconsistent handling of CEST time zone Oct 15, 2019
@bcmills bcmills added this to the Backlog milestone Oct 15, 2019
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 15, 2019

Timezone parsing depends on the information recorded on your system. If you see different information on different systems, it's because they have different timezone information. On GNU/Linux this information is stored in /usr/share/zoneinfo.

@infomaniac
Copy link
Author

@infomaniac infomaniac commented Oct 15, 2019

Thank you for picking up the issue.

CET might me deprecated, but so is MST which is widely used in the go documentation

@infomaniac
Copy link
Author

@infomaniac infomaniac commented Oct 15, 2019

Timezone parsing depends on the information recorded on your system. If you see different information on different systems, it's because they have different timezone information. On GNU/Linux this information is stored in /usr/share/zoneinfo.

Timezone parsing should only depend on the current system if not explicitly defined.
Even if it prints with different timezones, it's absolute value should be the same.
Therefor a Time.Sub(..) should return 0s duration.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 15, 2019

Your example expects CEST to map to a specific timezone offset (+0200). Your example explicitly expects 6:20 CEST to be the same as 4:20 UTC. Whether they are the same or not depends on the information your system has about the timezone CEST.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 15, 2019

CET might me deprecated, but so is MST which is widely used in the go documentation

@bcmills 's point is that while CET and MST are defined as IANA timezone names but are deprecated, CEST isn't defined at all.

In the tzdata database CEST (Central Europe Summer Time) is the timezone name printed for CST when in daylight savings time, but it doesn't seem to be recognized as a timezone name.

@gopherbot
Copy link

@gopherbot gopherbot commented Oct 15, 2019

Change https://golang.org/cl/201197 mentions this issue: time: avoid or clarify CEST

@infomaniac
Copy link
Author

@infomaniac infomaniac commented Oct 15, 2019

@bcmills 's point is that while CET and MST are defined as IANA timezone names but are deprecated, CEST isn't defined at all.

Correct. I agree.

I still believe there's a problem with time.Parse() as it behaves differently between Linux and Mac. (I cannot verify on Windows, sorry)

https://play.golang.org/p/xPnf-sz0E6W

On Docker/Linux and Playground the output is

[expected true ] parsedInUTC  equal: true -- 2019-09-06 10:00:00 +0000 UTC
[expected false] parsedInMST1 equal: true -- 2019-09-06 10:00:00 +0000 MST
[expected true ] parsedInMST2 equal: false -- 2019-09-06 03:00:00 +0000 MST
[expected true ] parsedInCET equal: false -- 2019-09-06 11:00:00 +0000 CET
[expected true ] parsedInLocation1 equal: true -- 2019-09-06 12:00:00 +0200 CEST
[expected true ] parsedInLocation2 equal: true -- 2019-09-06 10:00:00 +0000 UTC

On Mac it is

[expected true ] parsedInUTC  equal: true -- 2019-09-06 10:00:00 +0000 UTC
[expected false] parsedInMST1 equal: true -- 2019-09-06 10:00:00 +0000 MST
[expected true ] parsedInMST2 equal: false -- 2019-09-06 03:00:00 +0000 MST
[expected true ] parsedInCET equal: true -- 2019-09-06 12:00:00 +0200 CEST
[expected true ] parsedInLocation1 equal: true -- 2019-09-06 12:00:00 +0200 CEST
[expected true ] parsedInLocation2 equal: true -- 2019-09-06 10:00:00 +0000 UTC

What is confusing is that the same code behaves differently on Mac and Linux.
Also on Mac, CET is parsed correctly as a timezone, but MST not.

Sorry for being a nag.

gopherbot pushed a commit that referenced this issue Oct 15, 2019
In the tzdata database CEST is not recognized as a timezone name.
It is used as the abbreviated name for daylight saving time in
Central Europe.  Avoid using CEST in documentation as it suggests
that programs can parse dates that use CEST, which will typically
fail on Unix systems.

Updates #34913

Change-Id: I4b22f7d06607eb5b066812a48af58edd95498286
Reviewed-on: https://go-review.googlesource.com/c/go/+/201197
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Bryan C. Mills <bcmills@google.com>
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Oct 15, 2019

It is normal and expected for timezone parsing to differ on different systems, because it depends entirely on the timezone data present on the system.

From the output you show it appears that your Mac has data for the CET timezone but the playground and your GNU/Linux system do not.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 8, 2020

I don't think there is anything to do here, so I'm going to close this issue. Please comment if you disagree.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
5 participants
You can’t perform that action at this time.