1 Star 1 Fork 3

menuiis/gkit

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
d_time.go 1.04 KB
一键复制 编辑 原始数据 按行查看 历史
package timeout
import (
"database/sql/driver"
"fmt"
"strings"
"time"
)
type DTime time.Time
const DTimeFormat = "15:04:05"
func (d *DTime) UnmarshalJSON(src []byte) error {
return d.UnmarshalText(strings.Replace(string(src), "\"", "", -1))
}
func (d DTime) MarshalJSON() ([]byte, error) {
return []byte(`"` + d.String() + `"`), nil
}
func (d *DTime) UnmarshalText(value string) error {
dd, err := time.Parse(DTimeFormat, value)
if err != nil {
return err
}
*d = DTime(dd)
return nil
}
func (d DTime) String() string {
return (time.Time)(d).Format(DTimeFormat)
}
func (d *DTime) Scan(value interface{}) error {
switch v := value.(type) {
case []byte:
return d.UnmarshalText(string(v))
case string:
return d.UnmarshalText(v)
case time.Time:
*d = DTime(v)
case nil:
*d = DTime{}
default:
return fmt.Errorf("cannot sql.Scan() DBDate from: %#v", v)
}
return nil
}
func (d DTime) Value() (driver.Value, error) {
return driver.Value(time.Time(d).Format(DTimeFormat)), nil
}
func (DTime) GormDataType() string {
return "TIME"
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/menciis/gkit.git
git@gitee.com:menciis/gkit.git
menciis
gkit
gkit
d3f65ed26d21

搜索帮助