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: LoadLocation: ZONEINFO variable without effect on Windows #14276

Closed
geoko86 opened this issue Feb 9, 2016 · 3 comments
Closed

time: LoadLocation: ZONEINFO variable without effect on Windows #14276

geoko86 opened this issue Feb 9, 2016 · 3 comments

Comments

@geoko86
Copy link

geoko86 commented Feb 9, 2016

When you try to execute time.LoadLocation() on Windows program panic unless it finds zoneinfo.zip file in $GOROOT/lib/time/zoneinfo.zip. Even with ZONEINFO environment variable set you get the same panic.

Test program can be found here: http://play.golang.org/p/UgiIKSEiIP

Using golang 1.5.3 on Windows x86_64

Repro:

  1. Take program from playground, and compile locally on windows. (Cross compiling will result in $GOROOT pointing to $GOROOT of the original Mac OS X machine)
  2. Compile with go build and execute. Output should be something like this:

Found zoneinfo env: false, location: '' .
2009-11-11T07:00:00.0000+08:00

  1. Copy zoneinfo.zip from $GOROOT\lib\time\ to another location. E.g. C:\zoneinfo.zip
  2. Set ZONEINFO environment variable to point to previously copied zoneinfo E.g. set ZONEINFO=C:\zoneinfo.zip
  3. Move or delete your $GOROOT directory, so that it cannot be found anymore.
  4. Execute again

Expected output
Similar to output in step 2

Observed behavior
Program panics.

Found zoneinfo env: true, location: 'E:\zoneinfo.zip' .
open C:\Go\lib\time\zoneinfo.zip: The system cannot find the path specified.
panic: time: missing Location in call to Date

@geoko86 geoko86 changed the title time.LoadLocation: ZONEINFO variable without effect on Windows time: LoadLocation: ZONEINFO variable without effect on Windows Feb 9, 2016
@bradfitz bradfitz added this to the Unplanned milestone Feb 9, 2016
@bradfitz
Copy link
Contributor

bradfitz commented Feb 9, 2016

/cc @alexbrainman

@alexbrainman
Copy link
Member

@geoko86 I tried to follow your instructions. But I cannot reproduce your problem.

C:\a>go version
go version go1.5.3 windows/386

C:\a>type main.go
package main

import (
        "fmt"
        "syscall"
        "time"
)

func main() {
        zi, found := syscall.Getenv("ZONEINFO")
        fmt.Printf("Found zoneinfo env: %v, location: '%v' .\n", found, zi)

        str := getTimeString("Asia/Hong_Kong", time.Now())
        fmt.Println(str)
}

func getTimeString(strLocation string, ts time.Time) string {
        const MyRFC3339 = "2006-01-02T15:04:05.0000Z07:00"

        var loc *time.Location
        println("--------------")
        loc, err := time.LoadLocation(strLocation)
        if err != nil {
                fmt.Println(err)
                return ""
        }

        return ts.In(loc).Format(MyRFC3339)
}

C:\a>copy %GOROOT%\lib\time\zoneinfo.zip c:\
        1 file(s) copied.

C:\a>set ZONEINFO=C:\zoneinfo.zip

C:\a>go run main.go
Found zoneinfo env: true, location: 'C:\zoneinfo.zip' .
--------------
2016-02-11T14:01:45.7686+08:00

C:\a>del %GOROOT%\lib\time\zoneinfo.zip

C:\a>go run main.go
Found zoneinfo env: true, location: 'C:\zoneinfo.zip' .
--------------
2016-02-11T14:02:02.7219+08:00

C:\a>

What did I do wrong?

Alex

@geoko86
Copy link
Author

geoko86 commented Feb 11, 2016

@alexbrainman Thanks for checking.
It figured out what went wrong. I double checked the zoneinfo.zip that i was using and it turned out, that the copy was incomplete, only 105kB vs some 352kB.

When I copied it again and pointed ZONEINFO to it, it works.

The error message was not completely clear to me, would have expected something along the line "found zoneinfo.zip, but I cannot read it".

It is safe to close this as user error. :)

@golang golang locked and limited conversation to collaborators Feb 28, 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

4 participants