fix: 按业务时区同步昨日账单

- 固定按 Asia/Shanghai 计算账单昨日日期

- 补充 UTC 服务器时区回归测试
This commit is contained in:
Logan.Li committed 2026-07-29 05:57:07 +08:00
1 parent dd3770a66c
commit 65e2f09b97
2 files changed
+24 -1

No files matched your search

+10 -1
View File
@@ -23,7 +23,16 @@ type Result struct {
// Yesterday 昨日日期 YYYY-MM-DD
func Yesterday() string {
return time.Now().AddDate(0, 0, -1).Format("2006-01-02")
return billingYesterdayAt(time.Now())
}
// billingYesterdayAt 按平台业务时区计算昨日,避免服务器 UTC 时区造成日期偏差。 // Logan.Li
func billingYesterdayAt(now time.Time) string {
location, err := time.LoadLocation("Asia/Shanghai")
if err != nil {
location = time.FixedZone("CST", 8*60*60)
}
return now.In(location).AddDate(0, 0, -1).Format("2006-01-02")
}
// SyncDate 同步指定日期账单(全部或单个活跃云账号)
+14
View File
@@ -0,0 +1,14 @@
package billingsync
import (
"testing"
"time"
)
// TestBillingYesterdayAt 验证 UTC 服务器按中国业务时区计算昨日。 // Logan.Li
func TestBillingYesterdayAt(t *testing.T) {
now := time.Date(2026, 7, 28, 21, 30, 0, 0, time.UTC)
if got := billingYesterdayAt(now); got != "2026-07-28" {
t.Fatalf("昨日日期错误: got=%s want=2026-07-28", got)
}
}