30 Star 380 Fork 59

golang-module / carbon

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
database.go 865 Bytes
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2024-02-01 11:24 . ToStdTime->StdTime
package carbon
import (
"database/sql/driver"
"fmt"
"time"
)
// Scan an interface used by Scan in package database/sql for Scanning value from database to local golang variable.
func (c *Carbon) Scan(v interface{}) error {
if value, ok := v.(time.Time); ok {
loc, err := getLocationByTimezone(defaultTimezone)
if c.loc != nil {
loc = c.loc
}
*c = CreateFromStdTime(value)
c.loc, c.Error = loc, err
return nil
}
return fmt.Errorf("can not convert %v to carbon", v)
}
// Value the interface providing the Value method for package database/sql/driver.
func (c Carbon) Value() (driver.Value, error) {
if c.IsZero() {
return nil, nil
}
return c.StdTime(), nil
}
// GormDataType implements the interface GormDataTypeInterface for Carbon struct.
// 实现 GormDataTypeInterface 接口
func (c Carbon) GormDataType() string {
return "time"
}
Go
1
https://gitee.com/golang-module/carbon.git
git@gitee.com:golang-module/carbon.git
golang-module
carbon
carbon
master

搜索帮助