github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/pkg/platform/api/mediator/model/model.go (about) 1 package model 2 3 import ( 4 "time" 5 ) 6 7 const ( 8 ISO8601LocalTime = "2006-01-02T15:04:05" 9 ) 10 11 type Time struct { 12 time.Time 13 } 14 15 func (t *Time) UnmarshalJSON(data []byte) error { 16 // Ignore null, like in the main JSON package. 17 if string(data) == "null" { 18 return nil 19 } 20 var err error 21 t.Time, err = time.Parse(`"`+ISO8601LocalTime+`"`, string(data)) 22 return err 23 } 24 25 func (t *Time) MarshalJSON() ([]byte, error) { 26 d := make([]byte, 0, len(ISO8601LocalTime)+2) 27 d = append(d, '"') 28 d = t.Time.AppendFormat(d, ISO8601LocalTime) 29 d = append(d, '"') 30 return d, nil 31 }