]> Cypherpunks repositories - gostls13.git/commitdiff
time: handle zone file with no transitions
authorRuss Cox <rsc@golang.org>
Mon, 4 Feb 2013 03:41:00 +0000 (22:41 -0500)
committerRuss Cox <rsc@golang.org>
Mon, 4 Feb 2013 03:41:00 +0000 (22:41 -0500)
Code fix by Alex Bramley.

Fixes #4064.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7289049

src/pkg/time/time_test.go
src/pkg/time/zoneinfo_read.go

index 04b0ade242abd8004ae5b3923fdfdf50b8f652d8..3698c4fe2af356f686bc15747e4263b6dd40a3e1 100644 (file)
@@ -1265,6 +1265,22 @@ func TestCountMallocs(t *testing.T) {
        }
 }
 
+func TestLoadFixed(t *testing.T) {
+       // Issue 4064: handle locations without any zone transitions.
+       loc, err := LoadLocation("Etc/GMT+1")
+       if err != nil {
+               t.Fatal(err)
+       }
+
+       // The tzdata name Etc/GMT+1 uses "east is negative",
+       // but Go and most other systems use "east is positive".
+       // So GMT+1 corresponds to -3600 in the Go zone, not +3600.
+       name, offset := Now().In(loc).Zone()
+       if name != "GMT+1" || offset != -1*60*60 {
+               t.Errorf("Now().In(loc).Zone() = %q, %d, want %q, %d", name, offset, "GMT+1", -1*60*60)
+       }
+}
+
 func BenchmarkNow(b *testing.B) {
        for i := 0; i < b.N; i++ {
                t = Now()
index a5a2de218ef1a909b8441e060071db5b07e7117c..4519c996234ae0ae4d0f4bd1818174fef6e07018 100644 (file)
@@ -174,6 +174,12 @@ func loadZoneData(bytes []byte) (l *Location, err error) {
                }
        }
 
+       if len(tx) == 0 {
+               // Build fake transition to cover all time.
+               // This happens in fixed locations like "Etc/GMT0".
+               tx = append(tx, zoneTrans{when: -1 << 63, index: 0})
+       }
+
        // Committed to succeed.
        l = &Location{zone: zone, tx: tx}