From 9912df9ac6df3222f66d9fb4ec2a5690b4910a7a Mon Sep 17 00:00:00 2001 From: shanshanzhong Date: Mon, 20 Apr 2026 21:53:48 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BF=AE=E5=A4=8D=E6=97=B6=E5=8C=BA?= =?UTF-8?q?=E9=97=AE=E9=A2=98=20-=20FixedZone=20=E5=85=9C=E5=BA=95=20+=20D?= =?UTF-8?q?ockerfile=20=E5=A4=8D=E5=88=B6=E5=AE=8C=E6=95=B4=20zoneinfo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. ppanel.go: LoadLocation 失败时用 FixedZone("CST", +8h) 兜底 2. Dockerfile: 复制完整 /usr/share/zoneinfo 目录,确保 go-sql-driver 也能加载 Asia/Shanghai Co-Authored-By: claude-flow --- Dockerfile | 2 +- ppanel.go | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 74d41df..c040309 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,7 +28,7 @@ FROM scratch # Copy CA certificates and timezone data COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ -COPY --from=builder /usr/share/zoneinfo/Asia/Shanghai /usr/share/zoneinfo/Asia/Shanghai +COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo ENV TZ=Asia/Shanghai diff --git a/ppanel.go b/ppanel.go index 7fb787d..47d2c0c 100644 --- a/ppanel.go +++ b/ppanel.go @@ -8,12 +8,13 @@ import ( func init() { // Ensure time.Local matches DSN loc=Asia/Shanghai. - // In scratch Docker images, Go defaults to UTC even with TZ set, - // causing time range queries to shift by 8 hours. + // In scratch Docker images, LoadLocation may fail due to missing zoneinfo, + // so fall back to FixedZone as a guaranteed alternative. loc, err := time.LoadLocation("Asia/Shanghai") - if err == nil { - time.Local = loc + if err != nil { + loc = time.FixedZone("CST", 8*3600) } + time.Local = loc } func main() {