1
0
mirror of https://github.com/golang/go synced 2024-10-02 16:28:34 -06:00

time: fix parsing of minutes in time zones.

R=r
CC=golang-dev
https://golang.org/cl/1830041
This commit is contained in:
Adam Langley 2010-07-19 11:08:04 -04:00
parent dcd9d78549
commit 02786d263c
2 changed files with 12 additions and 1 deletions

View File

@ -522,7 +522,7 @@ func Parse(alayout, avalue string) (*Time, os.Error) {
}
var hr, min int
hr, err = strconv.Atoi(hh)
if err != nil {
if err == nil {
min, err = strconv.Atoi(mm)
}
t.ZoneOffset = (hr*60 + min) * 60 // offset is in seconds

View File

@ -303,6 +303,17 @@ func TestMissingZone(t *testing.T) {
}
}
func TestMinutesInTimeZone(t *testing.T) {
time, err := Parse(RubyDate, "Mon Jan 02 15:04:05 +0123 2006")
if err != nil {
t.Fatal("error parsing date:", err)
}
expected := (1*60 + 23) * 60
if time.ZoneOffset != expected {
t.Errorf("ZoneOffset incorrect, expected %d got %d", expected, time.ZoneOffset)
}
}
func BenchmarkSeconds(b *testing.B) {
for i := 0; i < b.N; i++ {
Seconds()