#441 fix detect timezone in mysql
Showing
1 changed file
with
9 additions
and
10 deletions
| ... | @@ -123,21 +123,18 @@ func RegisterDataBase(aliasName, driverName, dataSource string, params ...int) { | ... | @@ -123,21 +123,18 @@ func RegisterDataBase(aliasName, driverName, dataSource string, params ...int) { |
| 123 | 123 | ||
| 124 | switch al.Driver { | 124 | switch al.Driver { |
| 125 | case DR_MySQL: | 125 | case DR_MySQL: |
| 126 | row := al.DB.QueryRow("SELECT @@session.time_zone") | 126 | row := al.DB.QueryRow("SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP)") |
| 127 | var tz string | 127 | var tz string |
| 128 | row.Scan(&tz) | 128 | row.Scan(&tz) |
| 129 | if tz == "SYSTEM" { | 129 | if len(tz) >= 8 { |
| 130 | tz = "" | 130 | if tz[0] != '-' { |
| 131 | row = al.DB.QueryRow("SELECT @@system_time_zone") | 131 | tz = "+" + tz |
| 132 | row.Scan(&tz) | ||
| 133 | t, err := time.Parse("MST", tz) | ||
| 134 | if err == nil { | ||
| 135 | al.TZ = t.Location() | ||
| 136 | } | 132 | } |
| 137 | } else { | 133 | t, err := time.Parse("-07:00:00", tz) |
| 138 | t, err := time.Parse("-07:00", tz) | ||
| 139 | if err == nil { | 134 | if err == nil { |
| 140 | al.TZ = t.Location() | 135 | al.TZ = t.Location() |
| 136 | } else { | ||
| 137 | DebugLog.Printf("Detect DB timezone: %s %s\n", tz, err.Error()) | ||
| 141 | } | 138 | } |
| 142 | } | 139 | } |
| 143 | 140 | ||
| ... | @@ -163,6 +160,8 @@ func RegisterDataBase(aliasName, driverName, dataSource string, params ...int) { | ... | @@ -163,6 +160,8 @@ func RegisterDataBase(aliasName, driverName, dataSource string, params ...int) { |
| 163 | loc, err := time.LoadLocation(tz) | 160 | loc, err := time.LoadLocation(tz) |
| 164 | if err == nil { | 161 | if err == nil { |
| 165 | al.TZ = loc | 162 | al.TZ = loc |
| 163 | } else { | ||
| 164 | DebugLog.Printf("Detect DB timezone: %s %s\n", tz, err.Error()) | ||
| 166 | } | 165 | } |
| 167 | } | 166 | } |
| 168 | 167 | ... | ... |
-
Please register or sign in to post a comment