Initial commit: hugot lysenko
This commit is contained in:
32
handlers/quotedb/null_time.go
Normal file
32
handlers/quotedb/null_time.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package quotedb
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"time"
|
||||
)
|
||||
|
||||
// This is more or less exactly pq.NullTime
|
||||
type NullTime struct {
|
||||
Time time.Time
|
||||
Valid bool
|
||||
}
|
||||
|
||||
func (nt *NullTime) Scan(value interface{}) error {
|
||||
if value == nil {
|
||||
nt.Time, nt.Valid = time.Unix(0, 0).UTC(), false
|
||||
return nil
|
||||
}
|
||||
|
||||
nt.Valid = true
|
||||
nt.Time = value.(time.Time)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (nt *NullTime) Value() (driver.Value, error) {
|
||||
if !nt.Valid {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
return nt.Time, nil
|
||||
}
|
Reference in New Issue
Block a user