Commit 842a18c2 authored by Andrew Gerrand's avatar Andrew Gerrand

[release-branch.go1.2] time: correct path to time zone zip file on Unix

««« CL 19280043 / 9d199c7582d6
time: correct path to time zone zip file on Unix

Most Unix systems have their own time zone data,
so we almost never get far enough in the list to
discover that we cannot fall back to the zip file.
Adjust testing to exercise the final fallback.

Plan 9 and Windows were already correct
(and are the main users of the zip file).

R=golang-dev, bradfitz
CC=golang-dev
https://golang.org/cl/19280043
»»»

R=golang-dev
CC=golang-dev
https://golang.org/cl/20640043
parent 6ab0f588
...@@ -18,4 +18,7 @@ func ForceUSPacificForTesting() { ...@@ -18,4 +18,7 @@ func ForceUSPacificForTesting() {
localOnce.Do(initTestingZone) localOnce.Do(initTestingZone)
} }
var ParseTimeZone = parseTimeZone var (
ForceZipFileForTesting = forceZipFileForTesting
ParseTimeZone = parseTimeZone
)
...@@ -578,6 +578,16 @@ func TestParseInSydney(t *testing.T) { ...@@ -578,6 +578,16 @@ func TestParseInSydney(t *testing.T) {
} }
} }
func TestLoadLocationZipFile(t *testing.T) {
ForceZipFileForTesting(true)
defer ForceZipFileForTesting(false)
_, err := LoadLocation("Australia/Sydney")
if err != nil {
t.Fatal(err)
}
}
var rubyTests = []ParseTest{ var rubyTests = []ParseTest{
{"RubyDate", RubyDate, "Thu Feb 04 21:00:57 -0800 2010", true, true, 1, 0}, {"RubyDate", RubyDate, "Thu Feb 04 21:00:57 -0800 2010", true, true, 1, 0},
// Ignore the time zone in the test. If it parses, it'll be OK. // Ignore the time zone in the test. If it parses, it'll be OK.
......
...@@ -154,3 +154,7 @@ func loadLocation(name string) (*Location, error) { ...@@ -154,3 +154,7 @@ func loadLocation(name string) (*Location, error) {
} }
return nil, errors.New("unknown time zone " + name) return nil, errors.New("unknown time zone " + name)
} }
func forceZipFileForTesting(zipOnly bool) {
// We only use the zip file anyway.
}
...@@ -32,7 +32,19 @@ var zoneDirs = []string{ ...@@ -32,7 +32,19 @@ var zoneDirs = []string{
"/usr/share/zoneinfo/", "/usr/share/zoneinfo/",
"/usr/share/lib/zoneinfo/", "/usr/share/lib/zoneinfo/",
"/usr/lib/locale/TZ/", "/usr/lib/locale/TZ/",
runtime.GOROOT() + "/lib/time/zoneinfo/", runtime.GOROOT() + "/lib/time/zoneinfo.zip",
}
var origZoneDirs = zoneDirs
func forceZipFileForTesting(zipOnly bool) {
zoneDirs = make([]string, len(origZoneDirs))
copy(zoneDirs, origZoneDirs)
if zipOnly {
for i := 0; i < len(zoneDirs)-1; i++ {
zoneDirs[i] = "/XXXNOEXIST"
}
}
} }
func initLocal() { func initLocal() {
......
...@@ -264,3 +264,7 @@ func loadLocation(name string) (*Location, error) { ...@@ -264,3 +264,7 @@ func loadLocation(name string) (*Location, error) {
} }
return nil, errors.New("unknown time zone " + name) return nil, errors.New("unknown time zone " + name)
} }
func forceZipFileForTesting(zipOnly bool) {
// We only use the zip file anyway.
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment