Merge pull request #420 from jcsalem/master

Allow the database's timezone to be specified.
This commit is contained in:
Lunny Xiao 2016-07-13 20:19:06 -05:00 committed by GitHub
commit a61cf8e919
2 changed files with 6 additions and 1 deletions

View File

@ -41,6 +41,7 @@ type Engine struct {
logger core.ILogger logger core.ILogger
TZLocation *time.Location TZLocation *time.Location
DatabaseTZ *time.Location // The timezone of the database
disableGlobalCache bool 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) t := vv.Convert(core.TimeType).Interface().(time.Time)
z, _ := t.Zone() z, _ := t.Zone()
if len(z) == 0 || t.Year() == 0 { // !nashtsai! HACK tmp work around for lib/pq doesn't properly time with location 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()) 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 = 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 // !nashtsai! convert to engine location
if col.TimeZone == nil { if col.TimeZone == nil {