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