Skip to content

Commit

Permalink
Merge branch 'pr/73'
Browse files Browse the repository at this point in the history
Change-Id: I344ee4a78eccfb3f2e4357ec37f192fc0c6c0ace
  • Loading branch information
skriptble committed Aug 16, 2018
2 parents 81e026d + 28f4dc5 commit e3f321c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions bson/constructor.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,9 @@ func (ElementConstructor) DateTime(key string, dt int64) *Element {
}

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

// Null creates a null element with the given key.
Expand Down
6 changes: 3 additions & 3 deletions bson/constructor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,14 +279,14 @@ func TestConstructor(t *testing.T) {
// key
0x66, 0x6f, 0x6f, 0x0,
// value
0xC8, 0x6C, 0x3C, 0xAF, 0x60, 0x1, 0x0, 0x0,
0xC9, 0x6C, 0x3C, 0xAF, 0x60, 0x1, 0x0, 0x0,
}

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

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

requireElementsEqual(t, expected, actualTime)
requireElementsEqual(t, expected, actualDateTime)
Expand Down

0 comments on commit e3f321c

Please sign in to comment.