-
Notifications
You must be signed in to change notification settings - Fork 18k
time: LoadLocation(now.Local().Location().String()) != now.Local().Location() #15568
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
Comments
I try to use IDEA IntelliJ debugging. Found in the abbrev function But stdname, dstname :=abbrev(I) is the result of stdname = "" dstname="CST". C:\go\src\time\zoneinfo_windows.go func abbrev(z *syscall.Timezoneinformation) (std, dst string) {
stdName := syscall.UTF16ToString(z.StandardName[:])
a, ok := abbrs[stdName]
if !ok {
dstName := syscall.UTF16ToString(z.DaylightName[:])
// Perhaps stdName is not English. Try to convert it.
englishName, err := toEnglishName(stdName, dstName)
//[ DEBUG]englishName = "China Standard Time"
if err == nil {
a, ok = abbrs[englishName]
if ok {
// [DEBUG] a.std = "CST"
// [DEBUG] a.dst = "CST"
return a.std, a.dst
}
}
// fallback to using capital letters
return extractCAPS(stdName), extractCAPS(dstName)
}
return a.std, a.dst
} C:\go\src\time\zoneinfo_windows.go func initLocalFromTZI(i *syscall.Timezoneinformation) {
l := &localLoc
nzone := 1
if i.StandardDate.Month > 0 {
nzone++
}
l.zone = make([]zone, nzone)
stdname, dstname := abbrev(i)
// DEBUG stdname =""
// DEBUG dstname ="CST"
std := &l.zone[0]
std.name = stdname |
Also, now.Zone() normal. name,offset:=t.Zone()
fmt.Println(name,offset)
// output: CST 28800 |
Sorry, I don't think we guarantee that a time.Location's String() returns a unique key which can be used to load that For instance, I remember an old bug where something like LoadLocation("EST") could mean United State's east coast or Australia's east coast depending on who ran it. (I forget the details) Some similar old bugs: #4838 #3790 I don't think there's any code to change here, but maybe we just need to document the expectations better. |
What about this:
Does it look correct to you? Alex |
CL https://golang.org/cl/23078 mentions this issue. |
Local.String() returns "Local" on every OS, but windows. Change windows code to do like others. Updates #15568 Change-Id: I7a4d2713d940e2a01cff9d7f5cefc89def07546a Reviewed-on: https://go-review.googlesource.com/23078 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
CL https://golang.org/cl/31144 mentions this issue. |
CL 31144 is unrelated, sorry, I typed the wrong bug number into the commit message. This bug seems to be fixed by Alex's commit CL 23078. Now that Local.String() returns "Local" not "", everything is OK. |
Please answer these questions before submitting your issue. Thanks!
go version
)?go version go1.6.2 windows/amd64
go env
)?windows 10 x64
set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=D:\golang
set GORACE=
set GOROOT=c:\go
set GOTOOLDIR=c:\go\pkg\tool\windows_amd64
set GO15VENDOREXPERIMENT=1
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0
set CXX=g++
set CGO_ENABLED=1
Sorry, my English is not good.
now.Location().String() returns "Asia/ShangHai"
In non UTC time zone, time.LoadLocation(now.Local().Location().String()) != now.Local().Location()
now.Location() returns ""
now.Local().Location() returns ""
time.LoadLocation(now.Local().Location().String()) returns "UTC"
Is it bug, or is it just like that? I can't get the local time zone.
now.Location().String() returns ""
now.Local().Location().String() returns ""
l, err := time.LoadLocation("Local")
l.String() returns ""
t2, _ := time.Parse("2006-01-02T15:04:05.999999999Z07:00 MST", time.Now().Format("2006-01-02T15:04:05.999999999Z07:00 MST"))
t2.Location() returns ""
t2.Local().Location() returns ""
The text was updated successfully, but these errors were encountered: