]> Cypherpunks repositories - gostls13.git/commitdiff
[release-branch.go1.2] time: correct path to time zone zip file on Unix
authorAndrew Gerrand <adg@golang.org>
Fri, 1 Nov 2013 00:28:57 +0000 (11:28 +1100)
committerAndrew Gerrand <adg@golang.org>
Fri, 1 Nov 2013 00:28:57 +0000 (11:28 +1100)
««« 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

src/pkg/time/export_test.go
src/pkg/time/time_test.go
src/pkg/time/zoneinfo_plan9.go
src/pkg/time/zoneinfo_unix.go
src/pkg/time/zoneinfo_windows.go

index dbd553af49d81fd0bfb8b785839b92b24975e447..6cd535f6b197a76fdf55dd3d96c883451ae10459 100644 (file)
@@ -18,4 +18,7 @@ func ForceUSPacificForTesting() {
        localOnce.Do(initTestingZone)
 }
 
-var ParseTimeZone = parseTimeZone
+var (
+       ForceZipFileForTesting = forceZipFileForTesting
+       ParseTimeZone          = parseTimeZone
+)
index 22b751c5255b60b4680a7011ff3706f1c1703e7f..334c4b0cf737107a2db5e3670f5ff482a1567d73 100644 (file)
@@ -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{
        {"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.
index 6855238dc84f0b4c2456b93d066fd5dc14504b1a..0e8f3811bedc1d4d1919e9c717651dfffa5cb881 100644 (file)
@@ -154,3 +154,7 @@ func loadLocation(name string) (*Location, error) {
        }
        return nil, errors.New("unknown time zone " + name)
 }
+
+func forceZipFileForTesting(zipOnly bool) {
+       // We only use the zip file anyway.
+}
index 53b5dc82cb66b7b84623874002cc25bb1c80c8c7..fc5ae89fe5950eb6e63418051687579aeed4c449 100644 (file)
@@ -32,7 +32,19 @@ var zoneDirs = []string{
        "/usr/share/zoneinfo/",
        "/usr/share/lib/zoneinfo/",
        "/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() {
index 1e18ad295dfe6f3f609cad64631d806164911d2d..be4e5c13ff018104e1d86503b679dc7f68cc9efa 100644 (file)
@@ -264,3 +264,7 @@ func loadLocation(name string) (*Location, error) {
        }
        return nil, errors.New("unknown time zone " + name)
 }
+
+func forceZipFileForTesting(zipOnly bool) {
+       // We only use the zip file anyway.
+}