...

Source file src/pkg/time/zoneinfo_unix.go

     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.
     4	
     5	// +build aix darwin,386 darwin,amd64 dragonfly freebsd linux,!android nacl netbsd openbsd solaris
     6	
     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), https://en.wikipedia.org/wiki/Zoneinfo,
    10	// and ftp://munnari.oz.au/pub/oldtz/
    11	
    12	package time
    13	
    14	import (
    15		"syscall"
    16	)
    17	
    18	// Many systems use /usr/share/zoneinfo, Solaris 2 has
    19	// /usr/share/lib/zoneinfo, IRIX 6 has /usr/lib/locale/TZ.
    20	var zoneSources = []string{
    21		"/usr/share/zoneinfo/",
    22		"/usr/share/lib/zoneinfo/",
    23		"/usr/lib/locale/TZ/",
    24	}
    25	
    26	func initLocal() {
    27		// consult $TZ to find the time zone to use.
    28		// no $TZ means use the system default /etc/localtime.
    29		// $TZ="" means use UTC.
    30		// $TZ="foo" means use /usr/share/zoneinfo/foo.
    31	
    32		tz, ok := syscall.Getenv("TZ")
    33		switch {
    34		case !ok:
    35			z, err := loadLocation("localtime", []string{"/etc/"})
    36			if err == nil {
    37				localLoc = *z
    38				localLoc.name = "Local"
    39				return
    40			}
    41		case tz != "" && tz != "UTC":
    42			if z, err := loadLocation(tz, zoneSources); err == nil {
    43				localLoc = *z
    44				return
    45			}
    46		}
    47	
    48		// Fall back to UTC.
    49		localLoc.name = "UTC"
    50	}
    51	

View as plain text