|
|
|
@ -14,8 +14,9 @@ type BsonTime time.Time
|
|
|
|
|
func (bt BsonTime) MarshalJSON() ([]byte, error) {
|
|
|
|
|
|
|
|
|
|
b := make([]byte, 0)
|
|
|
|
|
|
|
|
|
|
b = append(b, '"')
|
|
|
|
|
b = append(b, gotime.SetCurrent(time.Time(bt)).Bson()...)
|
|
|
|
|
b = append(b, '"')
|
|
|
|
|
|
|
|
|
|
return b, nil
|
|
|
|
|
}
|
|
|
|
@ -28,20 +29,22 @@ func (bt *BsonTime) UnmarshalJSON(data []byte) (err error) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bsonTime := gotime.SetCurrentParse(string(data))
|
|
|
|
|
|
|
|
|
|
*bt = BsonTime(bsonTime.Time)
|
|
|
|
|
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Time 转时间
|
|
|
|
|
func (bt BsonTime) Time() time.Time {
|
|
|
|
|
return gotime.SetCurrent(time.Time(bt)).Time
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Format 转时间字符串
|
|
|
|
|
func (bt BsonTime) Format() string {
|
|
|
|
|
return gotime.SetCurrent(time.Time(bt)).Format()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// TimePro 转时间操作
|
|
|
|
|
func (bt BsonTime) TimePro() gotime.Pro {
|
|
|
|
|
return gotime.SetCurrent(time.Time(bt))
|
|
|
|
|
}
|
|
|
|
@ -68,17 +71,14 @@ func (bt BsonTime) Value() string {
|
|
|
|
|
|
|
|
|
|
// MarshalBSONValue 实现bson序列化
|
|
|
|
|
func (bt BsonTime) MarshalBSONValue() (bsontype.Type, []byte, error) {
|
|
|
|
|
//log.Println("MarshalBSONValue")
|
|
|
|
|
targetTime := gotime.SetCurrent(time.Time(bt)).Bson()
|
|
|
|
|
return bson.MarshalValue(targetTime)
|
|
|
|
|
return bson.MarshalValue(gotime.SetCurrent(time.Time(bt)).Bson())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UnmarshalBSONValue 实现bson反序列化
|
|
|
|
|
func (bt *BsonTime) UnmarshalBSONValue(t2 bsontype.Type, data []byte) error {
|
|
|
|
|
//log.Println("UnmarshalBSONValue")
|
|
|
|
|
func (bt *BsonTime) UnmarshalBSONValue(t bsontype.Type, data []byte) error {
|
|
|
|
|
t1 := gotime.SetCurrentParse(string(data))
|
|
|
|
|
//if string(data) == "" {
|
|
|
|
|
// return errors.New(fmt.Sprintf("%s, %s, %s", "读取数据失败:", t2, data))
|
|
|
|
|
// return errors.New(fmt.Sprintf("%s, %s, %s", "读取数据失败:", t, data))
|
|
|
|
|
//}
|
|
|
|
|
*bt = BsonTime(t1.Time)
|
|
|
|
|
return nil
|
|
|
|
|