Skip to content

Commit 04af4db

Browse files
tiskriptble
authored andcommitted
fix datetime json MarshalJSON
1 parent fcec76a commit 04af4db

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

bson/primitive/primitive.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ package primitive // import "go.mongodb.org/mongo-driver/bson/primitive"
1010

1111
import (
1212
"bytes"
13+
"encoding/json"
1314
"fmt"
15+
"time"
1416
)
1517

1618
// Binary represents a BSON binary value.
@@ -33,6 +35,11 @@ type Undefined struct{}
3335
// DateTime represents the BSON datetime value.
3436
type DateTime int64
3537

38+
// MarshalJSON marshal to time type
39+
func (d DateTime) MarshalJSON() ([]byte, error) {
40+
return json.Marshal(time.Unix(int64(d)/1000, int64(d)%1000*1000000))
41+
}
42+
3643
// Null repreesnts the BSON null value.
3744
type Null struct{}
3845

0 commit comments

Comments
 (0)