Skip to content

Commit d21a525

Browse files
Georgydomodwyer
authored andcommitted
bson.Unmarshal returns time in UTC (#42)
1 parent 950ed5a commit d21a525

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

bson/bson_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ var allItems = []testItemType{
146146
"\x08_\x00\x00"},
147147
{bson.M{"_": true},
148148
"\x08_\x00\x01"},
149-
{bson.M{"_": time.Unix(0, 258e6)}, // Note the NS <=> MS conversion.
149+
{bson.M{"_": time.Unix(0, 258e6).UTC()}, // Note the NS <=> MS conversion.
150150
"\x09_\x00\x02\x01\x00\x00\x00\x00\x00\x00"},
151151
{bson.M{"_": nil},
152152
"\x0A_\x00"},
@@ -1265,7 +1265,7 @@ var twoWayCrossItems = []crossTypeItem{
12651265
{&condPtr{&falsevar}, map[string]bool{"v": false}},
12661266
{&condPtr{}, map[string]string{}},
12671267

1268-
{&condTime{time.Unix(123456789, 123e6)}, map[string]time.Time{"v": time.Unix(123456789, 123e6)}},
1268+
{&condTime{time.Unix(123456789, 123e6).UTC()}, map[string]time.Time{"v": time.Unix(123456789, 123e6).UTC()}},
12691269
{&condTime{}, map[string]string{}},
12701270

12711271
{&condStruct{struct{ A []int }{[]int{1}}}, bson.M{"v": bson.M{"a": []interface{}{1}}}},
@@ -1320,8 +1320,8 @@ var twoWayCrossItems = []crossTypeItem{
13201320
{&struct{ V time.Time }{}, map[string]interface{}{"v": time.Time{}}},
13211321

13221322
// zero time + 1 second + 1 millisecond; overflows int64 as nanoseconds
1323-
{&struct{ V time.Time }{time.Unix(-62135596799, 1e6).Local()},
1324-
map[string]interface{}{"v": time.Unix(-62135596799, 1e6).Local()}},
1323+
{&struct{ V time.Time }{time.Unix(-62135596799, 1e6).UTC()},
1324+
map[string]interface{}{"v": time.Unix(-62135596799, 1e6).UTC()}},
13251325

13261326
// bson.D <=> []DocElem
13271327
{&bson.D{{"a", bson.D{{"b", 1}, {"c", 2}}}}, &bson.D{{"a", bson.D{{"b", 1}, {"c", 2}}}}},

bson/decode.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ func (d *decoder) readElemTo(out reflect.Value, kind byte) (good bool) {
575575
if i == -62135596800000 {
576576
in = time.Time{} // In UTC for convenience.
577577
} else {
578-
in = time.Unix(i/1e3, i%1e3*1e6)
578+
in = time.Unix(i/1e3, i%1e3*1e6).UTC()
579579
}
580580
case 0x0A: // Nil
581581
in = nil

0 commit comments

Comments
 (0)