Allow the database's timezone to be specified. See https://github.com/go-xorm/xorm/issues/419

This commit is contained in:
Jim Salem 2016-07-13 17:57:21 -04:00
parent 964132729e
commit ad5c1a5215
2 changed files with 6 additions and 1 deletions

View File

@ -41,6 +41,7 @@ type Engine struct {
logger core.ILogger
TZLocation *time.Location
DatabaseTZ *time.Location // The timezone of the database
disableGlobalCache bool
}

View File

@ -1816,9 +1816,13 @@ func (session *Session) _row2Bean(rows *core.Rows, fields []string, fieldsCount
t := vv.Convert(core.TimeType).Interface().(time.Time)
z, _ := t.Zone()
if len(z) == 0 || t.Year() == 0 { // !nashtsai! HACK tmp work around for lib/pq doesn't properly time with location
dbTZ := session.Engine.DatabaseTZ
if dbTZ == nil {
dbTZ = time.Local
}
session.Engine.logger.Debugf("empty zone key[%v] : %v | zone: %v | location: %+v\n", key, t, z, *t.Location())
t = time.Date(t.Year(), t.Month(), t.Day(), t.Hour(),
t.Minute(), t.Second(), t.Nanosecond(), time.Local)
t.Minute(), t.Second(), t.Nanosecond(), dbTZ)
}
// !nashtsai! convert to engine location
if col.TimeZone == nil {