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: Re-load ZONEINFO at runtime #18619

Closed
mappu opened this issue Jan 11, 2017 · 5 comments

Comments

Projects
None yet
5 participants
@mappu
Copy link

commented Jan 11, 2017

Hi,

On Windows, timezone calculations require presence of zoneinfo.zip file, which is found via the ZONEINFO environment variable. But in my situation, I am unable to set env vars, and it's not possible to re-set ZONEINFO after Go execution has already begun.

Would it be possible to add a method to time package to allow re-loading ZONEINFO from a custom path?

I tried os.Setenv() in main.init(), but, it had no effect, as below.

Right now i can only perform a workaround relaunching the binary with different environment.

Thanks


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

go version go1.7.3 windows/amd64

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

set GOARCH=amd64
set GOBIN=
set GOEXE=.exe
set GOHOSTARCH=amd64
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=
set GORACE=
set GOROOT=C:\Go
set GOTOOLDIR=C:\Go\pkg\tool\windows_amd64
set CC=gcc
set GOGCCFLAGS=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\cygwin\tmp\go-build715340254=/tmp/go-build -gno-record-gcc-switches
set CXX=g++
set CGO_ENABLED=1

What did you do?

package main

import (
	"fmt"
	"time"
	"os"
)

func init() {
	os.Setenv("ZONEINFO", `C:\valid\path\to\zoneinfo.zip`)
}

func main() {
	loc, err := time.LoadLocation("Europe/London")
	fmt.Printf("%v %v\n", loc, err)
}

What did you expect to see?

Europe/London <nil>

What did you see instead?

UTC open C:\Go\\lib\time\zoneinfo.zip: The system cannot find the file specified.

@bradfitz bradfitz added the OS-Windows label Jan 11, 2017

@bradfitz bradfitz added this to the Go1.9Maybe milestone Jan 11, 2017

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jan 11, 2017

Yeah, we could probably consult ZONEINFO lazily at the first call to LoadLocation, or check its modification after LoadLocation failures before subsequent LoadLocation calls.

@alexbrainman

This comment has been minimized.

Copy link
Member

commented Jan 11, 2017

Yeah, we could probably consult ZONEINFO

Or we could just introduce new time.LoadZONEINFO (or similar) function.

Alex

@bradfitz

This comment has been minimized.

Copy link
Member

commented Jan 11, 2017

Or we could just introduce new time.LoadZONEINFO (or similar) function.

The only thing grosser than new API for this is that name. :-)

@minux

This comment has been minimized.

Copy link
Member

commented Jan 11, 2017

@gopherbot

This comment has been minimized.

Copy link

commented Jan 24, 2017

CL https://golang.org/cl/35639 mentions this issue.

@gopherbot gopherbot closed this in 6d63606 Feb 1, 2017

@golang golang locked and limited conversation to collaborators Feb 1, 2018

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.