diff options
Diffstat (limited to 'libgo/go/time/zoneinfo.go')
-rw-r--r-- | libgo/go/time/zoneinfo.go | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/libgo/go/time/zoneinfo.go b/libgo/go/time/zoneinfo.go index aca56e746af..3c57744043e 100644 --- a/libgo/go/time/zoneinfo.go +++ b/libgo/go/time/zoneinfo.go @@ -4,7 +4,10 @@ package time -import "sync" +import ( + "sync" + "syscall" +) // A Location maps time instants to the zone in use at that time. // Typically, the Location represents the collection of time offsets @@ -168,10 +171,7 @@ func (l *Location) lookupOffset(offset int) (name string, isDST bool, ok bool) { // NOTE(rsc): Eventually we will need to accept the POSIX TZ environment // syntax too, but I don't feel like implementing it today. -// NOTE(rsc): Using the IANA names below means ensuring we have access -// to the database. Probably we will ship the files in $GOROOT/lib/zoneinfo/ -// and only look there if there are no system files available (such as on Windows). -// The files total 200 kB. +var zoneinfo, _ = syscall.Getenv("ZONEINFO") // LoadLocation returns the Location with the given name. // @@ -180,6 +180,13 @@ func (l *Location) lookupOffset(offset int) (name string, isDST bool, ok bool) { // // Otherwise, the name is taken to be a location name corresponding to a file // in the IANA Time Zone database, such as "America/New_York". +// +// The time zone database needed by LoadLocation may not be +// present on all systems, especially non-Unix systems. +// LoadLocation looks in the directory or uncompressed zip file +// named by the ZONEINFO environment variable, if any, then looks in +// known installation locations on Unix systems, +// and finally looks in $GOROOT/lib/time/zoneinfo.zip. func LoadLocation(name string) (*Location, error) { if name == "" || name == "UTC" { return UTC, nil @@ -187,5 +194,11 @@ func LoadLocation(name string) (*Location, error) { if name == "Local" { return Local, nil } + if zoneinfo != "" { + if z, err := loadZoneFile(zoneinfo, name); err == nil { + z.name = name + return z, nil + } + } return loadLocation(name) } |