mirror of
https://gitee.com/dromara/carbon.git
synced 2024-11-30 03:07:36 +08:00
24 lines
376 B
Go
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
|
|
}
|