v0.0.414 fix rfctime.Date bson marshalling for zero value
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 2m28s

This commit is contained in:
2024-03-16 19:42:59 +01:00
parent 6b4bd5a6f8
commit b704e2a362
4 changed files with 20 additions and 4 deletions

View File

@@ -102,6 +102,13 @@ func (t *Date) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
return err
}
if tt == "" {
t.Year = 0
t.Month = 0
t.Day = 0
return nil
}
v, err := time.Parse(t.FormatStr(), tt)
if err != nil {
return err
@@ -114,7 +121,10 @@ func (t *Date) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
}
func (t Date) MarshalBSONValue() (bsontype.Type, []byte, error) {
return bson.MarshalValue(t.TimeUTC().Format(t.FormatStr()))
if t.IsZero() {
return bson.MarshalValue("")
}
return bson.MarshalValue(t.String())
}
func (t Date) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val reflect.Value) error {
@@ -242,6 +252,10 @@ func (t *Date) ParseString(v string) error {
return nil
}
func (t Date) IsZero() bool {
return t.Year == 0 && t.Month == 0 && t.Day == 0
}
func NewDate(t time.Time) Date {
return Date{
Year: t.Year(),