Skip to content
This repository has been archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Commit

Permalink
fix time tag utc (#742)
Browse files Browse the repository at this point in the history
* fix time tag utc

* rename NowTime -> nowTime
  • Loading branch information
lunny authored Sep 30, 2017
1 parent c969050 commit 7dc8e76
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 9 deletions.
10 changes: 7 additions & 3 deletions engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1516,10 +1516,14 @@ func (engine *Engine) Import(r io.Reader) ([]sql.Result, error) {
return results, lastError
}

// NowTime2 return current time
func (engine *Engine) NowTime2(sqlTypeName string) (interface{}, time.Time) {
// nowTime return current time
func (engine *Engine) nowTime(col *core.Column) (interface{}, time.Time) {
t := time.Now()
return engine.formatTime(sqlTypeName, t.In(engine.DatabaseTZ)), t.In(engine.TZLocation)
var tz = engine.DatabaseTZ
if !col.DisableTimeZone && col.TimeZone != nil {
tz = col.TimeZone
}
return engine.formatTime(col.SQLType.Name, t.In(tz)), t.In(engine.TZLocation)
}

func (engine *Engine) formatColTime(col *core.Column, t time.Time) (v interface{}) {
Expand Down
2 changes: 1 addition & 1 deletion helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -422,7 +422,7 @@ func genCols(table *core.Table, session *Session, bean interface{}, useCol bool,

if (col.IsCreated || col.IsUpdated) && session.statement.UseAutoTime /*&& isZero(fieldValue.Interface())*/ {
// if time is non-empty, then set to auto time
val, t := session.engine.NowTime2(col.SQLType.Name)
val, t := session.engine.nowTime(col)
args = append(args, val)

var colName = col.Name
Expand Down
4 changes: 2 additions & 2 deletions session_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,12 +184,12 @@ func (session *Session) Delete(bean interface{}) (int64, error) {
}
}

// !oinume! Insert NowTime to the head of session.statement.Params
// !oinume! Insert nowTime to the head of session.statement.Params
condArgs = append(condArgs, "")
paramsLen := len(condArgs)
copy(condArgs[1:paramsLen], condArgs[0:paramsLen-1])

val, t := session.engine.NowTime2(deletedColumn.SQLType.Name)
val, t := session.engine.nowTime(deletedColumn)
condArgs[0] = val

var colName = deletedColumn.Name
Expand Down
4 changes: 2 additions & 2 deletions session_insert.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (session *Session) innerInsertMulti(rowsSlicePtr interface{}) (int64, error
}
}
if (col.IsCreated || col.IsUpdated) && session.statement.UseAutoTime {
val, t := session.engine.NowTime2(col.SQLType.Name)
val, t := session.engine.nowTime(col)
args = append(args, val)

var colName = col.Name
Expand Down Expand Up @@ -181,7 +181,7 @@ func (session *Session) innerInsertMulti(rowsSlicePtr interface{}) (int64, error
}
}
if (col.IsCreated || col.IsUpdated) && session.statement.UseAutoTime {
val, t := session.engine.NowTime2(col.SQLType.Name)
val, t := session.engine.nowTime(col)
args = append(args, val)

var colName = col.Name
Expand Down
2 changes: 1 addition & 1 deletion session_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int6
if _, ok := session.statement.columnMap[strings.ToLower(table.Updated)]; !ok {
colNames = append(colNames, session.engine.Quote(table.Updated)+" = ?")
col := table.UpdatedColumn()
val, t := session.engine.NowTime2(col.SQLType.Name)
val, t := session.engine.nowTime(col)
args = append(args, val)

var colName = col.Name
Expand Down

0 comments on commit 7dc8e76

Please sign in to comment.