Skip to content

Commit ec0d36b

Browse files
committed
Remove *Location in decoded time.Time values
GODRIVER-884 Change-Id: I1ef785f1ce1e9693e277d41c7a7b4672c411a551
1 parent 6191943 commit ec0d36b

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

bson/bsoncodec/bsoncodec_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"fmt"
1111
"reflect"
1212
"testing"
13+
"time"
1314

1415
"go.mongodb.org/mongo-driver/bson/bsonrw"
1516
"go.mongodb.org/mongo-driver/bson/bsontype"
@@ -53,6 +54,13 @@ func noerr(t *testing.T, err error) {
5354
}
5455
}
5556

57+
func compareTime(t1, t2 time.Time) bool {
58+
if t1.Location() != t2.Location() {
59+
return false
60+
}
61+
return t1.Equal(t2)
62+
}
63+
5664
func compareErrors(err1, err2 error) bool {
5765
if err1 == nil && err2 == nil {
5866
return true

bson/bsoncodec/default_value_decoders.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,7 @@ func (dvd DefaultValueDecoders) TimeDecodeValue(dc DecodeContext, vr bsonrw.Valu
614614
return ValueDecoderError{Name: "TimeDecodeValue", Types: []reflect.Type{tTime}, Received: val}
615615
}
616616

617-
val.Set(reflect.ValueOf(time.Unix(dt/1000, dt%1000*1000000)))
617+
val.Set(reflect.ValueOf(time.Unix(dt/1000, dt%1000*1000000).UTC()))
618618
return nil
619619
}
620620

bson/bsoncodec/default_value_decoders_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2035,7 +2035,7 @@ func TestDefaultValueDecoders(t *testing.T) {
20352035
oids := []primitive.ObjectID{primitive.NewObjectID(), primitive.NewObjectID(), primitive.NewObjectID()}
20362036
var str = new(string)
20372037
*str = "bar"
2038-
now := time.Now().Truncate(time.Millisecond)
2038+
now := time.Now().Truncate(time.Millisecond).UTC()
20392039
murl, err := url.Parse("https://mongodb.com/random-url?hello=world")
20402040
if err != nil {
20412041
t.Errorf("Error parsing URL: %v", err)
@@ -2573,6 +2573,7 @@ func TestDefaultValueDecoders(t *testing.T) {
25732573
cmp.Comparer(compareDecimal128),
25742574
cmp.Comparer(compareNoPrivateFields),
25752575
cmp.Comparer(compareZeroTest),
2576+
cmp.Comparer(compareTime),
25762577
); diff != "" {
25772578
t.Errorf("difference:\n%s", diff)
25782579
t.Errorf("Values are not equal.\ngot: %#v\nwant:%#v", got, want)

0 commit comments

Comments
 (0)