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: Date returns a Time object with incorrect offset for years 1900-1905 #30099

Closed
jinfengnarvar opened this issue Feb 5, 2019 · 6 comments

Comments

Projects
None yet
5 participants
@jinfengnarvar
Copy link

commented Feb 5, 2019

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

$ go version
go version go1.11.2 darwin/amd64

Does this issue reproduce with the latest release?

Don't know. I did repro this issue on https://play.golang.org/.

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

$ go env
GOARCH="amd64"
GOBIN="/Users/jinfeng/dev/narvar/go/bin"
GOCACHE="/Users/jinfeng/Library/Caches/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/jinfeng/dev/narvar/go"
GOPROXY=""
GORACE=""
GOROOT="/usr/local/opt/go/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/opt/go/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
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/x2/6yhw9qq129gffvpx90dv5gyw0000gp/T/go-build291093703=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Here is the repro code:

package main

import (
	"fmt"
	"time"
)

func main() {
	for i := 1900; i <= 1910; i++ {
		//tz := "Asia/Calcutta"
		tz := "America/New_York"
		loc, err := time.LoadLocation(tz)
		if err != nil {
			fmt.Println(i, "/", err)
			return
		}
		t := time.Date(i, time.January, 1, 0, 0, 0, 0, loc)
		tstr := t.Format(time.RFC3339)
		tzName, tzOffset := t.Zone()
		fmt.Println(tstr, "/", tzName, "/", tzOffset)
	}
}

What did you expect to see?

1900-01-01T00:00:00-05:00 / EST / -18000
1901-01-01T00:00:00-05:00 / EST / -18000
1902-01-01T00:00:00-05:00 / EST / -18000
1903-01-01T00:00:00-05:00 / EST / -18000
1904-01-01T00:00:00-05:00 / EST / -18000
1905-01-01T00:00:00-05:00 / EST / -18000
1906-01-01T00:00:00-05:00 / EST / -18000
1907-01-01T00:00:00-05:00 / EST / -18000
1908-01-01T00:00:00-05:00 / EST / -18000
1909-01-01T00:00:00-05:00 / EST / -18000
1910-01-01T00:00:00-05:00 / EST / -18000

What did you see instead?

1900-01-01T00:00:00-04:56 / LMT / -17762
1901-01-01T00:00:00-04:56 / LMT / -17762
1902-01-01T00:00:00-05:00 / EST / -18000
1903-01-01T00:00:00-05:00 / EST / -18000
1904-01-01T00:00:00-05:00 / EST / -18000
1905-01-01T00:00:00-05:00 / EST / -18000
1906-01-01T00:00:00-05:00 / EST / -18000
1907-01-01T00:00:00-05:00 / EST / -18000
1908-01-01T00:00:00-05:00 / EST / -18000
1909-01-01T00:00:00-05:00 / EST / -18000
1910-01-01T00:00:00-05:00 / EST / -18000

Similar output for "Asia/Calcutta" time zone, except the deviation lasts through 1905:

1900-01-01T00:00:00+05:53 / HMT / 21200
1901-01-01T00:00:00+05:53 / HMT / 21200
1902-01-01T00:00:00+05:21 / MMT / 19270
1903-01-01T00:00:00+05:21 / MMT / 19270
1904-01-01T00:00:00+05:21 / MMT / 19270
1905-01-01T00:00:00+05:21 / MMT / 19270
1906-01-01T00:08:50+05:30 / IST / 19800
1907-01-01T00:00:00+05:30 / IST / 19800
1908-01-01T00:00:00+05:30 / IST / 19800
1909-01-01T00:00:00+05:30 / IST / 19800
1910-01-01T00:00:00+05:30 / IST / 19800

@agnivade agnivade changed the title time.Date returns a time.Time object with incorrect offset when Format()'ed. time: Date returns a Time object with incorrect offset for years 1900-1905 Feb 6, 2019

@agnivade

This comment has been minimized.

Copy link
Member

commented Feb 6, 2019

@gopherbot

This comment has been minimized.

Copy link

commented Feb 6, 2019

Change https://golang.org/cl/161202 mentions this issue: time: read 64-bit data if available

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Feb 6, 2019

This is happening because we were only reading the 32-bit version of the tzdata info, which can't represent times before December 13, 1901.

@jinfengnarvar

This comment has been minimized.

Copy link
Author

commented Feb 6, 2019

@ianlancetaylor What about "Asia/Calcutta", of which the anomaly seems to continue beyond 1901.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Feb 6, 2019

It seems to me that with CL 161202 the times printed for "Asia/Calcutta" match the information in the tzdata database.

# Reed S, Low F. The Indian Year Book 1936-37. Bennett, Coleman, pp 27-8.
# https://archive.org/details/in.ernet.dli.2015.282212
# This lists +052110 as Madras local time used in railways, and says that on
# 1906-01-01 railways and telegraphs in India switched to +0530.  Some
# municipalities retained their former time, and the time in Calcutta
# continued to depend on whether you were at the railway station or at
# government offices.  Government time was at +055320 (according to Shanks) or
# at +0554 (according to the Indian Year Book).  Railway time is more
# appropriate for our purposes, as it was better documented, it is what we do
# elsewhere (e.g., Europe/London before 1880), and after 1906 it was
# consistent in the region now identified by Asia/Kolkata.  So, use railway
# time for 1870-1941.  Shanks is our only (and dubious) source for the
# 1941-1945 data.

# Zone	NAME		GMTOFF	RULES	FORMAT	[UNTIL]
Zone	Asia/Kolkata	5:53:28 -	LMT	1854 Jun 28 # Kolkata
			5:53:20	-	HMT	1870	    # Howrah Mean Time?
			5:21:10	-	MMT	1906 Jan  1 # Madras local time
			5:30	-	IST	1941 Oct
			5:30	1:00	+0630	1942 May 15
			5:30	-	IST	1942 Sep
			5:30	1:00	+0630	1945 Oct 15
			5:30	-	IST

@bradfitz bradfitz added the NeedsFix label Feb 6, 2019

@bradfitz bradfitz added this to the Go1.13 milestone Feb 6, 2019

@jinfengnarvar

This comment has been minimized.

Copy link
Author

commented Feb 6, 2019

Thanks @ianlancetaylor for investigation! And thanks @bradfitz for including the issue for next release!

In the meantime, I have my own wrapper around time.Date and limit the year to 1970 (an arbitrarily picked year that is just old enough :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.