Skip to content

Commit d16c4cb

Browse files
author
Divjot Arora
committed
Fix extended JSON parser for large dates.
GODRIVER-983 Change-Id: I4aa8435fcb39ec866d97a3dc7790a6307c3b92c2
1 parent 79bf126 commit d16c4cb

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

bson/bsonrw/extjson_parser_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,3 +716,21 @@ func TestExtJSONParserAllTypes(t *testing.T) {
716716
t.FailNow()
717717
}
718718
}
719+
720+
func TestExtJSONValue(t *testing.T) {
721+
t.Run("Large Date", func(t *testing.T) {
722+
val := &extJSONValue{
723+
t: bsontype.String,
724+
v: "3001-01-01T00:00:00Z",
725+
}
726+
727+
intVal, err := val.parseDateTime()
728+
if err != nil {
729+
t.Fatalf("error parsing date time: %v", err)
730+
}
731+
732+
if intVal <= 0 {
733+
t.Fatalf("expected value above 0, got %v", intVal)
734+
}
735+
})
736+
}

bson/bsonrw/extjson_wrappers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func parseDatetimeString(data string) (int64, error) {
203203
return 0, fmt.Errorf("invalid $date value string: %s", data)
204204
}
205205

206-
return t.UnixNano() / 1e6, nil
206+
return t.Unix()*1e3 + int64(t.Nanosecond())/1e6, nil
207207
}
208208

209209
func parseDatetimeObject(data *extJSONObject) (d int64, err error) {

0 commit comments

Comments
 (0)