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() {