Skip to content

Commit 61745d7

Browse files
authored
iso8601.Parse() timezone fix (#83)
1 parent 807cd3c commit 61745d7

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

iso8601/parse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func Parse(input string) (time.Time, error) {
5252
}
5353

5454
unixSeconds := int64(daysSinceEpoch(year, month, day))*86400 + int64(hour*3600+minute*60+second)
55-
return time.Unix(unixSeconds, 0), nil
55+
return time.Unix(unixSeconds, 0).UTC(), nil
5656

5757
case 24: // YYYY-MM-DDTHH:MM:SS.MMMZ
5858
t1 := binary.LittleEndian.Uint64(b)
@@ -89,7 +89,7 @@ func Parse(input string) (time.Time, error) {
8989
}
9090

9191
unixSeconds := int64(daysSinceEpoch(year, month, day))*86400 + int64(hour*3600+minute*60+second)
92-
return time.Unix(unixSeconds, int64(millis*1e6)), nil
92+
return time.Unix(unixSeconds, int64(millis*1e6)).UTC(), nil
9393

9494
default:
9595
return time.Parse(time.RFC3339Nano, input)

iso8601/parse_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ func TestParse(t *testing.T) {
4242
t.Error(err)
4343
} else if !actual.Equal(expect) {
4444
t.Errorf("unexpected time: %v vs expected %v", actual, expect)
45+
} else if actual.Location().String() != expect.Location().String() {
46+
t.Errorf("unexpected timezone: %v vs expected %v", actual.Location().String(), expect.Location().String())
4547
}
4648
})
4749
}

0 commit comments

Comments
 (0)