1
0
mirror of https://github.com/astaxie/beego.git synced 2024-11-25 23:01:28 +00:00

orm detect mysql timezone #403

This commit is contained in:
slene 2013-12-21 21:00:29 +08:00
parent 2c868a9557
commit fc339fc3e0

View File

@ -126,7 +126,15 @@ func RegisterDataBase(aliasName, driverName, dataSource string, params ...int) {
row := al.DB.QueryRow("SELECT @@session.time_zone") row := al.DB.QueryRow("SELECT @@session.time_zone")
var tz string var tz string
row.Scan(&tz) row.Scan(&tz)
if tz != "SYSTEM" { if tz == "SYSTEM" {
tz = ""
row = al.DB.QueryRow("SELECT @@system_time_zone")
row.Scan(&tz)
t, err := time.Parse("MST", tz)
if err == nil {
al.TZ = t.Location()
}
} else {
t, err := time.Parse("-07:00", tz) t, err := time.Parse("-07:00", tz)
if err == nil { if err == nil {
al.TZ = t.Location() al.TZ = t.Location()