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: time.Time get wrong local time zone for some days #16553

Closed
lysu opened this issue Jul 31, 2016 · 6 comments
Closed

time: time.Time get wrong local time zone for some days #16553

lysu opened this issue Jul 31, 2016 · 6 comments

Comments

@lysu
Copy link

lysu commented Jul 31, 2016

Hi,

I have create time.Time for 1986-05-04 using time.Date(), and then use Zone() or Format to display it...

but for 1986-05-04, timeZone will be CDT +09:00, not my Local time in China(+08:00), but for 2017-08-01 it works well...

I try to read code in time.Date(), it will do some adjust when time second too close to a zone transition...so it first get CDT then adjust to CST, but haven't found that in other time.lookup() usage, and they return CDT directly, what about this?- -

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

go1.6.2

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

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/didi/Code/go:/Users/didi/.gvm/pkgsets/go1.6.2/global"
GORACE=""
GOROOT="/Users/didi/.gvm/gos/go1.6.2"
GOTOOLDIR="/Users/didi/.gvm/gos/go1.6.2/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1"

and I'm in China.. CST +08:00

  1. What did you do?

run a simple main.go

package main

import (
    "fmt"
    "time"
)

func main() {
    tt := time.Date(1986, 5, 4, 0, 0, 0, 0, time.Local)
    z, offset := tt.Zone()
    fmt.Println(z, offset, tt.Format(time.RFC3339))

    tt = time.Date(2016, 8, 1, 0, 0, 0, 0, time.Local)
    z, offset = tt.Zone()
    fmt.Println(z, offset, tt.Format(time.RFC3339))
}
  1. What did you expect to see?

    CST 28800 1986-05-04T00:00:00+08:00
    CST 28800 2016-08-01T00:00:00+08:00

  2. What did you see instead?

    CDT 32400 1986-05-04T01:00:00+09:00
    CST 28800 2016-08-01T00:00:00+08:00

@lysu lysu changed the title time: time.Time time: time.Time get wrong local time zone for some days Jul 31, 2016
@lysu
Copy link
Author

lysu commented Jul 31, 2016

and for my /etc/localtime can download from here~

https://github.com/lysu/go-misc/blob/master/localtime

@lysu
Copy link
Author

lysu commented Jul 31, 2016

continue.. I found that 2017 is work well because it use cacheZone- - , but use day before 1991 will use zoneTrans and get wrong zone- -

@catalase
Copy link

catalase commented Jul 31, 2016

It seems there is something wrong in lib/time/timezone.zip.

I tried to reproduce the issue of timezone to verify whether the issue is up to your computer or not. Actually, I could reproduce error identical to your error. This implies the issue is a bug of Go.

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

The above depicts the bug, not why happens, for these who don't live in China, such as me living in Korea.

I think that the bug stems from lib/time/timezone.zip which Go uses to determine the information of local timezone of your computer. It may be a workaround that you do not use the information given by lib/time/timezone.zip, then use time.Local = time.FixedZone("CST", 3600*8) instead.

@lysu
Copy link
Author

lysu commented Jul 31, 2016

oh~~ It seem be Daylight Saving Time question..

+09:00 mean DST...not Tokyo Time...But In China we doesn't use Daylight Saving Time.. - -

@lysu
Copy link
Author

lysu commented Jul 31, 2016

  • - before 1991, China has Daylight Saving Time...so it is not a bug...

Closed ...

thx @catalase

@lysu lysu closed this as completed Jul 31, 2016
@catalase
Copy link

catalase commented Aug 1, 2016

I didn't consider dst! learn something new today.

@golang golang locked and limited conversation to collaborators Aug 1, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants