carbon/database.go
2021-07-03 15:31:42 +08:00

24 lines
376 B
Go

package carbon
import (
"database/sql/driver"
"fmt"
"time"
)
func (c *Carbon) Scan(v interface{}) error {
value, ok := v.(time.Time)
if ok {
*c = Carbon{Time: value, Loc: time.Local}
return nil
}
return fmt.Errorf("can not convert %v to timestamp", v)
}
func (c Carbon) Value() (driver.Value, error) {
if c.IsZero() {
return nil, nil
}
return c.Time, nil
}