Skip to content

Commit b72c904

Browse files
committed
Adds time struct encoding in valueFromValue.
1 parent 06bdfb1 commit b72c904

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

bson/encode.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -669,11 +669,18 @@ func (e *encoder) valueFromValue(val reflect.Value, minsize bool) (*Value, error
669669
elem = VC.ArrayFromValues(arrayElems...)
670670
}
671671
case reflect.Struct:
672-
structElems, err := e.encodeStruct(val)
673-
if err != nil {
674-
return nil, err
672+
switch val.Interface().(type) {
673+
case time.Time:
674+
t := val.Interface().(time.Time)
675+
676+
elem = VC.DateTime(t.UnixNano() / int64(time.Millisecond))
677+
default:
678+
structElems, err := e.encodeStruct(val)
679+
if err != nil {
680+
return nil, err
681+
}
682+
elem = VC.DocumentFromElements(structElems...)
675683
}
676-
elem = VC.DocumentFromElements(structElems...)
677684
default:
678685
return nil, fmt.Errorf("Unsupported value type %s", val.Kind())
679686
}

0 commit comments

Comments
 (0)