Skip to content

Commit e3f321c

Browse files
committed
Merge branch 'pr/73'
Change-Id: I344ee4a78eccfb3f2e4357ec37f192fc0c6c0ace
2 parents 81e026d + 28f4dc5 commit e3f321c

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

bson/constructor.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,8 +341,9 @@ func (ElementConstructor) DateTime(key string, dt int64) *Element {
341341
}
342342

343343
// Time creates a datetime element with the given key and value.
344-
func (c ElementConstructor) Time(key string, time time.Time) *Element {
345-
return c.DateTime(key, time.Unix()*1000)
344+
func (c ElementConstructor) Time(key string, t time.Time) *Element {
345+
// Apply nanoseconds to milliseconds conversion
346+
return c.DateTime(key, t.UnixNano()/int64(time.Millisecond))
346347
}
347348

348349
// Null creates a null element with the given key.

bson/constructor_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -279,14 +279,14 @@ func TestConstructor(t *testing.T) {
279279
// key
280280
0x66, 0x6f, 0x6f, 0x0,
281281
// value
282-
0xC8, 0x6C, 0x3C, 0xAF, 0x60, 0x1, 0x0, 0x0,
282+
0xC9, 0x6C, 0x3C, 0xAF, 0x60, 0x1, 0x0, 0x0,
283283
}
284284

285285
expected := &Element{&Value{start: 0, offset: 5, data: buf, d: nil}}
286286

287-
date := time.Date(2018, 1, 1, 1, 1, 1, 1, time.UTC)
287+
date := time.Date(2018, 1, 1, 1, 1, 1, int(1*time.Millisecond), time.UTC)
288288
actualTime := EC.Time("foo", date)
289-
actualDateTime := EC.DateTime("foo", date.Unix()*1000)
289+
actualDateTime := EC.DateTime("foo", date.UnixNano()/1e6)
290290

291291
requireElementsEqual(t, expected, actualTime)
292292
requireElementsEqual(t, expected, actualDateTime)

0 commit comments

Comments
 (0)