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:
@@ -7,6 +7,8 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"aiaa-notification-service/internal/tz"
|
||||
)
|
||||
|
||||
type envelope struct {
|
||||
@@ -95,7 +97,7 @@ func Convert(body []byte) (string, map[string]interface{}, error) {
|
||||
}
|
||||
mergePayloadFields(data, payloadJSON)
|
||||
if env.EventTime > 0 {
|
||||
data["pushedAt"] = time.UnixMilli(env.EventTime).In(time.Local).Format("2006-01-02 15:04:05")
|
||||
data["pushedAt"] = tz.Format(time.UnixMilli(env.EventTime), "2006-01-02 15:04:05")
|
||||
}
|
||||
if p.TotalGainTarget != 0 {
|
||||
data["totalGainTarget"] = p.TotalGainTarget
|
||||
@@ -260,7 +262,7 @@ func format(env envelope, p payload, action string) string {
|
||||
lines = append(lines, fmt.Sprintf("策略: %s", p.StrategyCode))
|
||||
}
|
||||
if env.EventTime > 0 {
|
||||
t := time.UnixMilli(env.EventTime).In(time.Local)
|
||||
t := time.UnixMilli(env.EventTime).In(tz.CST)
|
||||
lines = append(lines, fmt.Sprintf("Time: %s", t.Format("2006.01.02 15:04:05")))
|
||||
}
|
||||
return strings.Join(lines, "\n")
|
||||
|
||||
Reference in New Issue
Block a user