sorare/types/iso8601datetime.go

24 lines
473 B
Go

package types
import "time"
type ISO8601DateTime time.Time
func NewISO8601DateTime(t time.Time) *ISO8601DateTime {
i := ISO8601DateTime(t)
return &i
}
func (i *ISO8601DateTime) UnmarshalJSON(b []byte) error {
t, err := time.Parse(`"2006-01-02T15:04:05Z"`, string(b))
if err != nil {
return err
}
*i = ISO8601DateTime(t)
return nil
}
func (i ISO8601DateTime) MarshalJSON() ([]byte, error) {
return []byte(time.Time(i).Format(`"2006-01-02T15:04:05Z"`)), nil
}