mirror of
https://github.com/astaxie/beego.git
synced 2024-11-22 08:30:54 +00:00
#441 fix detect timezone in mysql
This commit is contained in:
parent
844412c302
commit
8d79f8387b
@ -123,21 +123,18 @@ func RegisterDataBase(aliasName, driverName, dataSource string, params ...int) {
|
|||||||
|
|
||||||
switch al.Driver {
|
switch al.Driver {
|
||||||
case DR_MySQL:
|
case DR_MySQL:
|
||||||
row := al.DB.QueryRow("SELECT @@session.time_zone")
|
row := al.DB.QueryRow("SELECT TIMEDIFF(NOW(), UTC_TIMESTAMP)")
|
||||||
var tz string
|
var tz string
|
||||||
row.Scan(&tz)
|
row.Scan(&tz)
|
||||||
if tz == "SYSTEM" {
|
if len(tz) >= 8 {
|
||||||
tz = ""
|
if tz[0] != '-' {
|
||||||
row = al.DB.QueryRow("SELECT @@system_time_zone")
|
tz = "+" + tz
|
||||||
row.Scan(&tz)
|
|
||||||
t, err := time.Parse("MST", tz)
|
|
||||||
if err == nil {
|
|
||||||
al.TZ = t.Location()
|
|
||||||
}
|
}
|
||||||
} else {
|
t, err := time.Parse("-07:00:00", tz)
|
||||||
t, err := time.Parse("-07:00", tz)
|
|
||||||
if err == nil {
|
if err == nil {
|
||||||
al.TZ = t.Location()
|
al.TZ = t.Location()
|
||||||
|
} else {
|
||||||
|
DebugLog.Printf("Detect DB timezone: %s %s\n", tz, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -163,6 +160,8 @@ func RegisterDataBase(aliasName, driverName, dataSource string, params ...int) {
|
|||||||
loc, err := time.LoadLocation(tz)
|
loc, err := time.LoadLocation(tz)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
al.TZ = loc
|
al.TZ = loc
|
||||||
|
} else {
|
||||||
|
DebugLog.Printf("Detect DB timezone: %s %s\n", tz, err.Error())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user