aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2013-11-01 11:28:57 +1100
committerAndrew Gerrand <adg@golang.org>2013-11-01 11:28:57 +1100
commit842a18c28f5b42a77e0d5b8f6bc26f01b771a69b (patch)
tree7176c6cbba178890ee57b46993fddfa340fd79ae
parent6ab0f588a89ecde66607c0dcefd44de2b9a47dd0 (diff)
downloadgo-842a18c28f5b42a77e0d5b8f6bc26f01b771a69b.tar.gz
go-842a18c28f5b42a77e0d5b8f6bc26f01b771a69b.zip
[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
-rw-r--r--src/pkg/time/export_test.go5
-rw-r--r--src/pkg/time/time_test.go10
-rw-r--r--src/pkg/time/zoneinfo_plan9.go4
-rw-r--r--src/pkg/time/zoneinfo_unix.go14
-rw-r--r--src/pkg/time/zoneinfo_windows.go4
5 files changed, 35 insertions, 2 deletions
diff --git a/src/pkg/time/export_test.go b/src/pkg/time/export_test.go
index dbd553af49..6cd535f6b1 100644
--- a/src/pkg/time/export_test.go
+++ b/src/pkg/time/export_test.go
@@ -18,4 +18,7 @@ func ForceUSPacificForTesting() {
localOnce.Do(initTestingZone)
}
-var ParseTimeZone = parseTimeZone
+var (
+ ForceZipFileForTesting = forceZipFileForTesting
+ ParseTimeZone = parseTimeZone
+)
diff --git a/src/pkg/time/time_test.go b/src/pkg/time/time_test.go
index 22b751c525..334c4b0cf7 100644
--- a/src/pkg/time/time_test.go
+++ b/src/pkg/time/time_test.go
@@ -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.
diff --git a/src/pkg/time/zoneinfo_plan9.go b/src/pkg/time/zoneinfo_plan9.go
index 6855238dc8..0e8f3811be 100644
--- a/src/pkg/time/zoneinfo_plan9.go
+++ b/src/pkg/time/zoneinfo_plan9.go
@@ -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.
+}
diff --git a/src/pkg/time/zoneinfo_unix.go b/src/pkg/time/zoneinfo_unix.go
index 53b5dc82cb..fc5ae89fe5 100644
--- a/src/pkg/time/zoneinfo_unix.go
+++ b/src/pkg/time/zoneinfo_unix.go
@@ -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() {
diff --git a/src/pkg/time/zoneinfo_windows.go b/src/pkg/time/zoneinfo_windows.go
index 1e18ad295d..be4e5c13ff 100644
--- a/src/pkg/time/zoneinfo_windows.go
+++ b/src/pkg/time/zoneinfo_windows.go
@@ -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.
+}