You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
698 B
43 lines
698 B
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
|
|
}
|
|
|