v0.0.405
All checks were successful
Build Docker and Deploy / Run goext test-suite (push) Successful in 1m36s

This commit is contained in:
Mike Schwörer 2024-03-10 15:28:26 +01:00
parent 102a280dda
commit 0927fdc4d7
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
2 changed files with 7 additions and 23 deletions

View File

@ -1,5 +1,5 @@
package goext package goext
const GoextVersion = "0.0.404" const GoextVersion = "0.0.405"
const GoextVersionTimestamp = "2024-03-10T15:25:30+0100" const GoextVersionTimestamp = "2024-03-10T15:28:26+0100"

View File

@ -67,36 +67,20 @@ func (t *Date) UnmarshalJSON(data []byte) error {
if err := json.Unmarshal(data, &str); err != nil { if err := json.Unmarshal(data, &str); err != nil {
return err return err
} }
t0, err := time.Parse(t.FormatStr(), str) return t.ParseString(str)
if err != nil {
return err
}
t.Year = t0.Year()
t.Month = int(t0.Month())
t.Day = t0.Day()
return nil
} }
func (t Date) MarshalJSON() ([]byte, error) { func (t Date) MarshalJSON() ([]byte, error) {
str := t.TimeUTC().Format(t.FormatStr()) str := t.String()
return json.Marshal(str) return json.Marshal(str)
} }
func (t Date) MarshalText() ([]byte, error) { func (t Date) MarshalText() ([]byte, error) {
b := make([]byte, 0, len(t.FormatStr())) return []byte(t.String()), nil
return t.TimeUTC().AppendFormat(b, t.FormatStr()), nil
} }
func (t *Date) UnmarshalText(data []byte) error { func (t *Date) UnmarshalText(data []byte) error {
var err error return t.ParseString(string(data))
v, err := time.Parse(t.FormatStr(), string(data))
if err != nil {
return err
}
t.Year = v.Year()
t.Month = int(v.Month())
t.Day = v.Day()
return nil
} }
func (t *Date) UnmarshalBSONValue(bt bsontype.Type, data []byte) error { func (t *Date) UnmarshalBSONValue(bt bsontype.Type, data []byte) error {
@ -166,7 +150,7 @@ func (t Date) DecodeValue(dc bsoncodec.DecodeContext, vr bsonrw.ValueReader, val
} }
func (t Date) Serialize() string { func (t Date) Serialize() string {
return t.TimeUTC().Format(t.FormatStr()) return t.String()
} }
func (t Date) FormatStr() string { func (t Date) FormatStr() string {