🐛 fix(mysql): 修复旧版 Windows 无法解析 Asia/Shanghai 时区

- 嵌入 Go IANA 时区数据,兼容 Windows Server 2012 等缺少 zoneinfo 的环境
- 保持 MySQL serverTimezone=GMT+8 到 loc=Asia/Shanghai 的时间语义
- 增加 MySQL DSN 时区解析回归测试
Refs #449
This commit is contained in:
Syngnat
2026-05-10 17:29:11 +08:00
parent 947bdbbe0c
commit c0ae40c638
2 changed files with 29 additions and 0 deletions

View File

@@ -1,6 +1,7 @@
package db
import (
"database/sql"
"net/url"
"strings"
"testing"
@@ -121,6 +122,28 @@ func TestMySQLDSN_MapsJDBCUTF8EncodingToMySQLCharset(t *testing.T) {
}
}
func TestMySQLDSN_AsiaShanghaiLocationAcceptedByDriver(t *testing.T) {
t.Parallel()
m := &MySQLDB{}
dsn, err := m.getDSN(connection.ConnectionConfig{
Host: "127.0.0.1",
Port: 3306,
User: "root",
Database: "app",
ConnectionParams: "serverTimezone=GMT%2B8",
})
if err != nil {
t.Fatalf("getDSN failed: %v", err)
}
db, err := sql.Open("mysql", dsn)
if err != nil {
t.Fatalf("mysql driver should accept loc=Asia/Shanghai: %v", err)
}
_ = db.Close()
}
func TestMySQLDSN_URIParamsAndExplicitParamsPrecedence(t *testing.T) {
t.Parallel()

View File

@@ -0,0 +1,6 @@
package db
// Embed the IANA time zone database so Windows deployments without zoneinfo
// files, such as Windows Server 2012, can still resolve locations like
// Asia/Shanghai when database drivers parse DSN time zone parameters.
import _ "time/tzdata"