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: cannot find zone on Windows #3437

Closed
gopherbot opened this issue Mar 30, 2012 · 11 comments

Comments

Projects
None yet
5 participants
@gopherbot
Copy link

commented Mar 30, 2012

by sanat.gersappa:

My system Time Zone is UTC +5:30

fmt.Println(time.Now().Zone()) prints UTC 0

Expected output: UTC + offset in seconds

OS: Windows 7 Professional 32-bit (Intel)
Go Version: go1
Compiler: 8g
@gopherbot

This comment has been minimized.

Copy link
Author

commented Mar 30, 2012

Comment 1 by sanat.gersappa:

Tried again on the same machine with Linux Mint 12 (3.0.0.13) 32-bit. Output is IST
19800.
@rsc

This comment has been minimized.

Copy link
Contributor

commented Mar 30, 2012

Comment 2:

This would happen if (and I believe only if) syscall.GetTimeZoneInformation fails.
Can you let us know what this program prints on your Windows system?
package main
import (
    "fmt"
    "syscall"
)
func main() {
    var i syscall.Timezoneinformation
    _, err := syscall.GetTimeZoneInformation(&i)
    if err != nil {
        fmt.Printf("ERR: %v\n", err)
    } else {
        fmt.Printf("TZI: %+v\n", i)
    }
}
Thanks.

Labels changed: added priority-later, removed priority-triage.

Status changed to WaitingForReply.

@gopherbot

This comment has been minimized.

Copy link
Author

commented Mar 30, 2012

Comment 3 by sanat.gersappa:

The code you pasted prints this:
TZI: {Bias:-330 StandardName:[73 110 100 105 97 32 83 116 97 110 100 97 114 100 32 84
105 109 101 0 0 0 0 0 0 0 0 0 0 0 0 0] StandardDate:{Year:0 Month:0 DayOfWeek:0 Day:0
Hour:0 Minute:0 Second:0 Milliseconds:0} StandardBias:0 DaylightName:[73 110 100 105 97
32 68 97 121 108 105 103 104 116 32 84 105 109 101 0 0 0 0 0 0 0 0 0 0 0 0 0]
DaylightDate:{Year:0 Month:0 DayOfWeek:0 Day:0 Hour:0 Minute:0 Second:0 Milliseconds:0}
DaylightBias:-60}
@rsc

This comment has been minimized.

Copy link
Contributor

commented Mar 30, 2012

Comment 4:

Thanks.  I was definitely expecting an error and not actual information.  Strange.
If you could indulge me in one more program, can you check whether printing
time.Local.String() prints "UTC" or "Local"?  If it prints "UTC" that will confirm 
that, somehow, syscall.GetTimeZoneInformation failed on startup even though
it is working for you when called from main.  If it prints "Local" then I will be
even more confused.
The zone information in your output looks completely reasonable: it says that the
zone is at +5:30 and is named "India Standard Time", with no switch to daylight
savings time.  If presented with that information during initialization, it looks to
me like package time would correctly be showing IST +5:30.
If time.Local.String() prints "UTC" the question is why did the syscall fail during
startup.  If time.Local.String() prints "Local" the question is why did the init not
record the results (or perhaps not run at all).
If you would like to try to debug this, the relevant code is
src/pkg/time/zoneinfo_windows.go's initLocal.  You can't import fmt in that package, but
you can use the built-in print.  I would try adding these prints:
func initLocal() {
println("initLocal called")
    var i syscall.Timezoneinformation
    if _, err := syscall.GetTimeZoneInformation(&i); err != nil {
println("GTZI failed:", err.Error())
        localLoc.name = "UTC"
        return
    }
println("GTZI success")
    initLocalFromTZI(&i)
}
and then 'go install time' and re-build and re-run your program that prints
time.Now().Zone().
@gopherbot

This comment has been minimized.

Copy link
Author

commented Mar 30, 2012

Comment 5 by sanat.gersappa:

Thanks.
time.Local().String() prints UTC.
I added the code to zoneinfo_windows.go. Zone() still prints "UTC 0"
time.Local().String() now prints:
initLocal called
GTZI success
2012-03-30 20:37:47.5652908 +0000 UTC
so it appears that the syscall succeeds, but still gets the wrong time zone.
@alexbrainman

This comment has been minimized.

Copy link
Member

commented Apr 2, 2012

Comment 6:

I think we do not handle timezones with no DST properly. Here is proposed fix
http://golang.org/cl/5967063/.
Alex

Labels changed: added os-windows, packagebug.

Owner changed to @alexbrainman.

Status changed to Started.

@alexbrainman

This comment has been minimized.

Copy link
Member

commented Apr 3, 2012

Comment 7:

This issue was closed by revision d3c92b7.

Status changed to Fixed.

@alexbrainman

This comment has been minimized.

Copy link
Member

commented Apr 25, 2012

Comment 8:

This issue was closed by revision d7a83c7dfab4.

@dsymonds

This comment has been minimized.

Copy link
Member

commented May 6, 2012

Comment 9:

Issue #3592 has been merged into this issue.

@gopherbot

This comment has been minimized.

Copy link
Author

commented Feb 10, 2014

Comment 10 by achun.SHX:

Why time.Local.String() prints ""?
call println(time.Now().In(time.Local).Zone()) output:
CST 28800
call syscall.GetTimeZoneInformation got such as:
syscall.Timezoneinformation{
    StandardName: "中国标准时间",
    DaylightName: "中国夏令时",
    Bias:         -480,
    StandardDate: syscall.Systemtime{
        Year:         0x0,
        Month:        0x0,
        DayOfWeek:    0x0,
        Day:          0x0,
        Hour:         0x0,
        Minute:       0x0,
        Second:       0x0,
        Milliseconds: 0x0},
    StandardBias: 0,
    DaylightDate: syscall.Systemtime{
        Year:         0x0,
        Month:        0x0,
        DayOfWeek:    0x0,
        Day:          0x0,
        Hour:         0x0,
        Minute:       0x0,
        Second:       0x0,
        Milliseconds: 0x0,
    },
    DaylightBias: -60,
}
OS: Windows 7 ultimate 64-bit (Intel)
Go Version: go1.2
Compiler: 6g
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Feb 10, 2014

Comment 11:

Please don't add comments to issues that were closed long ago.  Instead ask the question
on golang-nuts@googlegroups.com, or open a new issue.  Thanks.

alexbrainman added a commit that referenced this issue May 11, 2015

[release-branch.go1] time: fix handling of locations with no dst on w…
…indows

««« backport 701af83040ac
time: fix handling of locations with no dst on windows

Fixes #3437.

R=rsc
CC=golang-dev
https://golang.org/cl/5967063
»»»

@golang golang locked and limited conversation to collaborators Jun 24, 2016

This issue was closed.

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