fix(时区): 推送时间统一使用 UTC+8 而非服务器本地时区

Motivation:
推送时间原先依赖 time.Local,部署在不同时区的服务器会产生不一致的展示结果。统一为 UTC+8,确保所有订阅者看到的时间固定为北京时间。

Changes:

* 新增 internal/tz 时区工具,集中定义 UTC+8 与格式化逻辑
* 通知、crypto 策略、交易信号的时间渲染统一改用 UTC+8
* 补充测试断言 pushedAt 为 UTC+8 当前时间
* 更新 README 中关于注入时间的说明

Breaking Changes:
所有推送时间字段将按 UTC+8 展示,若服务部署在非 UTC+8 时区且依赖原本地时间行为,输出会发生变化。
This commit is contained in:
2026-08-17 01:29:13 +08:00
parent d2e8476398
commit a93078dc00
7 changed files with 49 additions and 6 deletions
+2 -1
View File
@@ -13,6 +13,7 @@ import (
"aiaa-notification-service/internal/condition"
"aiaa-notification-service/internal/engine"
"aiaa-notification-service/internal/model"
"aiaa-notification-service/internal/tz"
)
var ErrUnprocessable = errors.New("unprocessable")
@@ -71,7 +72,7 @@ func (s *Service) Process(ctx context.Context, req Request) (Result, error) {
req.Data["event"] = req.Event
}
if _, ok := req.Data["pushedAt"]; !ok {
req.Data["pushedAt"] = time.Now().In(time.Local).Format("2006.01.02 15:04:05")
req.Data["pushedAt"] = tz.Format(time.Now(), "2006.01.02 15:04:05")
}
var channels []string
+11
View File
@@ -6,6 +6,7 @@ import (
"errors"
"strings"
"testing"
"time"
"aiaa-notification-service/internal/engine"
"aiaa-notification-service/internal/model"
@@ -153,6 +154,16 @@ func TestProcessInjectsPushedAt(t *testing.T) {
if !strings.Contains(rt.content, "推送时间:") {
t.Fatalf("content=%q", rt.content)
}
got := strings.TrimPrefix(rt.content, "推送时间:")
got = strings.TrimSpace(got)
cst := time.FixedZone("CST", 8*3600)
parsed, err := time.ParseInLocation("2006.01.02 15:04:05", got, cst)
if err != nil {
t.Fatalf("parse %q: %v", got, err)
}
if d := time.Since(parsed); d < -2*time.Second || d > 2*time.Second {
t.Fatalf("pushedAt %q is not UTC+8 now, drift=%s", got, d)
}
}
func TestProcessInvalidConditions(t *testing.T) {