diff --git a/README.md b/README.md index 425372d9..a2a46fbb 100644 --- a/README.md +++ b/README.md @@ -89,6 +89,8 @@ Or # Cases +* [Gorevel](http://http://gorevel.cn/) - [github.com/goofcc/gorevel](http://github.com/goofcc/gorevel) + * [Gogs](http://try.gogits.org) - [github.com/gogits/gogs](http://github.com/gogits/gogs) * [Gowalker](http://gowalker.org) - [github.com/Unknwon/gowalker](http://github.com/Unknwon/gowalker) diff --git a/engine.go b/engine.go index f98ea4c7..b21e8e85 100644 --- a/engine.go +++ b/engine.go @@ -1075,6 +1075,11 @@ func (engine *Engine) Import(ddlPath string) ([]sql.Result, error) { } func (engine *Engine) TZTime(t time.Time) (r time.Time) { + if t.Location() == nil { + return time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), + t.Minute(), t.Second(), t.Nanosecond(), engine.TZLocation()) + } + switch engine.TimeZone { case "Local", "L": r = t.Local() @@ -1104,6 +1109,7 @@ func (engine *Engine) NowTime(sqlTypeName string) interface{} { } func (engine *Engine) FormatTime(sqlTypeName string, t time.Time) (v interface{}) { + fmt.Println("sqlTypeName:", sqlTypeName) switch sqlTypeName { case Time: s := engine.TZTime(t).Format("2006-01-02 15:04:05") //time.RFC3339 @@ -1111,7 +1117,9 @@ func (engine *Engine) FormatTime(sqlTypeName string, t time.Time) (v interface{} case Date: v = engine.TZTime(t).Format("2006-01-02") case DateTime, TimeStamp: - v = engine.TZTime(t).Format("2006-01-02 15:04:05") + l := engine.TZTime(t) + v = l.Format("2006-01-02 15:04:05") + fmt.Println("xxxx", t, l, v, engine.TimeZone) case TimeStampz: if engine.dialect.DBType() == MSSQL { v = engine.TZTime(t).Format("2006-01-02T15:04:05.9999999Z07:00") diff --git a/session.go b/session.go index 50431043..aac0887b 100644 --- a/session.go +++ b/session.go @@ -1492,7 +1492,17 @@ func (session *Session) row2Bean(rows *sql.Rows, fields []string, fieldsCount in if fieldType == reflect.TypeOf(c_TIME_DEFAULT) { if rawValueType == reflect.TypeOf(c_TIME_DEFAULT) { hasAssigned = true - fieldValue.Set(vv) + if true { + t := vv.Interface().(time.Time) + f := time.Date(t.Year(), t.Month(), t.Day(), t.Hour(), + t.Minute(), t.Second(), t.Nanosecond(), session.Engine.TZLocation()) + fieldValue.Set(reflect.ValueOf(f)) + } else { + fieldValue.Set(vv) + } + } else { + // TODO: + fmt.Println("=====unknow time type", rawValueType) } } else if session.Statement.UseCascade { table := session.Engine.autoMapType(*fieldValue) diff --git a/statement.go b/statement.go index 88185303..c9161be7 100644 --- a/statement.go +++ b/statement.go @@ -333,6 +333,7 @@ func buildConditions(engine *Engine, table *Table, bean interface{}, continue } val = engine.FormatTime(col.SQLType.Name, t) + fmt.Println("-------", t, val, col.Name) } else { engine.autoMapType(fieldValue) if table, ok := engine.Tables[fieldValue.Type()]; ok {