1 // Copyright 2009 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // +build darwin dragonfly freebsd linux nacl netbsd openbsd solaris
7 // Parse "zoneinfo" time zone file.
8 // This is a fairly standard file format used on OS X, Linux, BSD, Sun, and others.
9 // See tzfile(5), http://en.wikipedia.org/wiki/Zoneinfo,
10 // and ftp://munnari.oz.au/pub/oldtz/
20 func initTestingZone() {
21 syscall
.Setenv("TZ", "America/Los_Angeles")
25 // Many systems use /usr/share/zoneinfo, Solaris 2 has
26 // /usr/share/lib/zoneinfo, IRIX 6 has /usr/lib/locale/TZ.
27 var zoneDirs
= []string{
28 "/usr/share/zoneinfo/",
29 "/usr/share/lib/zoneinfo/",
30 "/usr/lib/locale/TZ/",
31 runtime
.GOROOT() + "/lib/time/zoneinfo.zip",
34 var origZoneDirs
= zoneDirs
36 func forceZipFileForTesting(zipOnly
bool) {
37 zoneDirs
= make([]string, len(origZoneDirs
))
38 copy(zoneDirs
, origZoneDirs
)
40 for i
:= 0; i
< len(zoneDirs
)-1; i
++ {
41 zoneDirs
[i
] = "/XXXNOEXIST"
47 // consult $TZ to find the time zone to use.
48 // no $TZ means use the system default /etc/localtime.
49 // $TZ="" means use UTC.
50 // $TZ="foo" means use /usr/share/zoneinfo/foo.
52 tz
, ok
:= syscall
.Getenv("TZ")
55 z
, err
:= loadZoneFile("", "/etc/localtime")
58 localLoc
.name
= "Local"
61 case tz
!= "" && tz
!= "UTC":
62 if z
, err
:= loadLocation(tz
); err
== nil {
72 func loadLocation(name
string) (*Location
, error
) {
73 for _
, zoneDir
:= range zoneDirs
{
74 if z
, err
:= loadZoneFile(zoneDir
, name
); err
== nil {
79 return nil, errors
.New("unknown time zone " + name
)