From ad5c1a52159969a5324c0c1e4195c95846851ffd Mon Sep 17 00:00:00 2001 From: Jim Salem Date: Wed, 13 Jul 2016 17:57:21 -0400 Subject: [PATCH] Allow the database's timezone to be specified. See https://github.com/go-xorm/xorm/issues/419 --- engine.go | 1 + session.go | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/engine.go b/engine.go index cc4670be..04e2b0a4 100644 --- a/engine.go +++ b/engine.go @@ -41,6 +41,7 @@ type Engine struct { logger core.ILogger TZLocation *time.Location + DatabaseTZ *time.Location // The timezone of the database disableGlobalCache bool } diff --git a/session.go b/session.go index f6490f38..35e7a306 100644 --- a/session.go +++ b/session.go @@ -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 {