Fix time
This commit is contained in:
parent
1139445b2e
commit
9b1e746c6c
|
@ -10,8 +10,8 @@ import (
|
|||
"strconv"
|
||||
)
|
||||
|
||||
// ConvertAssignString converts an interface to string
|
||||
func ConvertAssignString(v interface{}) (string, error) {
|
||||
// Interface2String converts an interface to string
|
||||
func Interface2String(v interface{}) (string, error) {
|
||||
if v == nil {
|
||||
return "", nil
|
||||
}
|
||||
|
|
17
engine.go
17
engine.go
|
@ -82,7 +82,12 @@ func newEngine(driverName, dataSourceName string, dialect dialects.Dialect, db *
|
|||
dataSourceName: dataSourceName,
|
||||
db: db,
|
||||
logSessionID: false,
|
||||
DatabaseTZ: time.Local,
|
||||
}
|
||||
|
||||
if dialect.URI().DBType == schemas.SQLITE {
|
||||
engine.DatabaseTZ = time.UTC
|
||||
} else {
|
||||
engine.DatabaseTZ = time.Local
|
||||
}
|
||||
|
||||
logger := log.NewSimpleLogger(os.Stdout)
|
||||
|
@ -469,8 +474,6 @@ func formatColumnValue(dbLocation *time.Location, dstDialect dialects.Dialect, d
|
|||
return "NULL"
|
||||
}
|
||||
|
||||
fmt.Printf("%#v------%v\n", d, col.Name)
|
||||
|
||||
if dq, ok := d.(bool); ok && (dstDialect.URI().DBType == schemas.SQLITE ||
|
||||
dstDialect.URI().DBType == schemas.MSSQL) {
|
||||
if dq {
|
||||
|
@ -1297,6 +1300,14 @@ func (engine *Engine) Import(r io.Reader) ([]sql.Result, error) {
|
|||
return session.Import(r)
|
||||
}
|
||||
|
||||
func (engine *Engine) columnTime(col *schemas.Column, t *time.Time) interface{} {
|
||||
var tz = engine.DatabaseTZ
|
||||
if !col.DisableTimeZone && col.TimeZone != nil {
|
||||
tz = col.TimeZone
|
||||
}
|
||||
return t.In(tz)
|
||||
}
|
||||
|
||||
// nowTime return current time
|
||||
func (engine *Engine) nowTime(col *schemas.Column) (interface{}, time.Time) {
|
||||
t := time.Now()
|
||||
|
|
|
@ -562,6 +562,11 @@ func (session *Session) genInsertColumns(bean interface{}) ([]string, []interfac
|
|||
if err != nil {
|
||||
return colNames, args, err
|
||||
}
|
||||
if t, ok := arg.(time.Time); ok {
|
||||
arg = session.engine.columnTime(col, &t)
|
||||
} else if t, ok := arg.(*time.Time); ok {
|
||||
arg = session.engine.columnTime(col, t)
|
||||
}
|
||||
args = append(args, arg)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue