package dts import ( "database/sql" "database/sql/driver" "encoding/json" ) type NullTime sql.NullTime func (nt *NullTime) Scan(value any) error { st := new(sql.NullTime) err := st.Scan(value) nt.Time = st.Time nt.Valid = st.Valid return err } func (nt NullTime) Value() (driver.Value, error) { if !nt.Valid { return nil, nil } return nt.Time, nil } func (nt NullTime) MarshalJSON() ([]byte, error) { if nt.Valid { return nt.Time.MarshalJSON() } return json.Marshal(nil) } func (nt *NullTime) UnmarshalJSON(b []byte) error { if string(b) == "null" { nt.Valid = false return nil } err := json.Unmarshal(b, &nt.Time) if err == nil { nt.Valid = true } return err }