update time
continuous-integration/drone/push Build is failing Details

master v1.0.2
李光春 2 years ago
parent ce96abecb0
commit 4c466d3aa1

@ -1,21 +0,0 @@
MIT License
Copyright (c) 2018 茂名聚合科技有限公司
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

@ -3,6 +3,7 @@ module go.dtapp.net/golog
go 1.18
require (
go.dtapp.net/gotime v1.0.2
gorm.io/datatypes v1.0.6
gorm.io/gorm v1.23.5
)

@ -122,6 +122,8 @@ github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81P
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
go.dtapp.net/gotime v1.0.2 h1:CFIJHQXC/4t9bsJhk2cLhjHd6rpdPcJXr8BcHKHDuQo=
go.dtapp.net/gotime v1.0.2/go.mod h1:Gq7eNLr2iMLP18UNWONRq4V3Uhf/ADp4bIrS+Tc6ktY=
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.4.0/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
go.uber.org/atomic v1.5.0/go.mod h1:sABNBOSYdrvTF6hTgEIbc7YasKWGhgEQZyfxyTvoXHQ=

@ -0,0 +1,48 @@
package golog
import (
"database/sql/driver"
"errors"
"fmt"
"go.dtapp.net/gotime"
"gorm.io/gorm"
"gorm.io/gorm/schema"
"time"
)
type TimeString time.Time
// GormDataType gorm通用数据类型
func (t TimeString) GormDataType() string {
return "string"
}
func (t TimeString) GormDBDataType(db *gorm.DB, field *schema.Field) string {
// 使用 field.Tag、field.TagSettings 获取字段的 tag
// 查看 https://github.com/go-gorm/gorm/blob/master/schema/field.go 获取全部的选项
// 根据不同的数据库驱动返回不同的数据类型
switch db.Dialector.Name() {
case "mysql", "sqlite":
return "string"
case "postgres":
return "string"
}
return ""
}
// Scan 实现 sql.Scanner 接口Scan 将 value 扫描至 Time
func (t *TimeString) Scan(value interface{}) error {
str, ok := value.(string)
if !ok {
return errors.New(fmt.Sprint("无法解析:", value))
}
t1 := gotime.SetCurrentParse(str).Time
*t = TimeString(t1)
return nil
}
// Value 实现 driver.Valuer 接口Value 返回 string value
func (t TimeString) Value() (driver.Value, error) {
return gotime.SetCurrent(time.Time(t)).Format(), nil
}

@ -1,3 +1,3 @@
package golog
const Version = "1.0.1"
const Version = "1.0.2"

Loading…
Cancel
Save