Retro68/gcc/libgo/go/time/zoneinfo_unix.go

53 lines
1.3 KiB
Go
Raw Normal View History

2012-03-27 23:13:14 +00:00
// Copyright 2009 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
2019-06-02 15:48:37 +00:00
// +build aix darwin,386 darwin,amd64 dragonfly freebsd hurd js,wasm linux,!android nacl netbsd openbsd solaris
2012-03-27 23:13:14 +00:00
// Parse "zoneinfo" time zone file.
// This is a fairly standard file format used on OS X, Linux, BSD, Sun, and others.
2019-06-02 15:48:37 +00:00
// See tzfile(5), https://en.wikipedia.org/wiki/Zoneinfo,
2012-03-27 23:13:14 +00:00
// and ftp://munnari.oz.au/pub/oldtz/
package time
import (
"runtime"
"syscall"
)
// Many systems use /usr/share/zoneinfo, Solaris 2 has
// /usr/share/lib/zoneinfo, IRIX 6 has /usr/lib/locale/TZ.
2018-12-28 15:30:48 +00:00
var zoneSources = []string{
2012-03-27 23:13:14 +00:00
"/usr/share/zoneinfo/",
"/usr/share/lib/zoneinfo/",
"/usr/lib/locale/TZ/",
2014-09-21 17:33:12 +00:00
runtime.GOROOT() + "/lib/time/zoneinfo.zip",
}
2012-03-27 23:13:14 +00:00
func initLocal() {
// consult $TZ to find the time zone to use.
// no $TZ means use the system default /etc/localtime.
// $TZ="" means use UTC.
// $TZ="foo" means use /usr/share/zoneinfo/foo.
tz, ok := syscall.Getenv("TZ")
switch {
case !ok:
2018-12-28 15:30:48 +00:00
z, err := loadLocation("localtime", []string{"/etc/"})
2012-03-27 23:13:14 +00:00
if err == nil {
localLoc = *z
localLoc.name = "Local"
return
}
case tz != "" && tz != "UTC":
2018-12-28 15:30:48 +00:00
if z, err := loadLocation(tz, zoneSources); err == nil {
2012-03-27 23:13:14 +00:00
localLoc = *z
return
}
}
// Fall back to UTC.
localLoc.name = "UTC"
}