1
0
mirror of https://github.com/golang/go synced 2024-11-22 08:54:39 -07:00

time: handle zone file with no transitions

Code fix by Alex Bramley.

Fixes #4064.

R=golang-dev, adg
CC=golang-dev
https://golang.org/cl/7289049
This commit is contained in:
Russ Cox 2013-02-03 22:41:00 -05:00
parent 0df8c7517e
commit 6a003d7589
2 changed files with 22 additions and 0 deletions

View 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) { func BenchmarkNow(b *testing.B) {
for i := 0; i < b.N; i++ { for i := 0; i < b.N; i++ {
t = Now() t = Now()

View 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. // Committed to succeed.
l = &Location{zone: zone, tx: tx} l = &Location{zone: zone, tx: tx}