v0.0.80
This commit is contained in:
@@ -2,6 +2,10 @@ package rfctime
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/bson/bsontype"
|
||||
"time"
|
||||
)
|
||||
|
||||
@@ -61,6 +65,23 @@ func (t *RFC3339Time) UnmarshalText(data []byte) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t *RFC3339Time) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
|
||||
if bt != bsontype.DateTime {
|
||||
return errors.New(fmt.Sprintf("cannot unmarshal %v into RFC3339Time", bt))
|
||||
}
|
||||
var tt time.Time
|
||||
err := bson.Unmarshal(data, &tt)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
*t = RFC3339Time(tt)
|
||||
return nil
|
||||
}
|
||||
|
||||
func (t RFC3339Time) MarshalBSONValue() (bsontype.Type, []byte, error) {
|
||||
return bson.MarshalValue(time.Time(t))
|
||||
}
|
||||
|
||||
func (t RFC3339Time) Serialize() string {
|
||||
return t.Time().Format(t.FormatStr())
|
||||
}
|
||||
|
Reference in New Issue
Block a user