1 Star 0 Fork 59

golang-package / carbon

forked from golang-module / carbon 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
database.go 867 Bytes
一键复制 编辑 原始数据 按行查看 历史
gouguoyin 提交于 2024-01-07 19:59 . Optimize code
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.ToStdTime(), nil
}
// GormDataType implements the interface GormDataTypeInterface for Carbon struct.
// 实现 GormDataTypeInterface 接口
func (c Carbon) GormDataType() string {
return "time"
}
Go
1
https://gitee.com/golang-package/carbon.git
git@gitee.com:golang-package/carbon.git
golang-package
carbon
carbon
v2.3.6

搜索帮助

53164aa7 5694891 3bd8fe86 5694891