修复(#128): 兼容促销规则毫秒时间戳
Build docker and publish / build (20.15.1) (push) Failing after 19m21s
Build docker and publish / build (20.15.1) (pull_request) Failing after 19m48s

Co-authored-by: multica-agent <github@multica.ai>
This commit is contained in:
2026-05-30 04:16:21 -07:00
parent 0659a930f8
commit 1e99cfb83c
3 changed files with 184 additions and 8 deletions
+34 -4
View File
@@ -17,11 +17,24 @@ const (
subscribeCachePref = "promo:subscribe:"
)
var (
minPromoRuleTime = time.Date(1970, 1, 1, 0, 0, 0, 0, time.UTC)
maxPromoRuleTime = time.Date(9999, 12, 31, 23, 59, 59, 0, time.UTC)
)
func validateRuleInput(ruleType string, params map[string]interface{}, priority int64, startTime, endTime *int64) error {
if priority < 0 {
return errors.Wrapf(xerr.NewErrCode(xerr.InvalidParams), "priority must be greater than or equal to 0")
}
if startTime != nil && endTime != nil && *startTime >= *endTime {
startAt, err := normalizeRuleTimestamp(startTime)
if err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.InvalidParams), "invalid start_time")
}
endAt, err := normalizeRuleTimestamp(endTime)
if err != nil {
return errors.Wrapf(xerr.NewErrCode(xerr.InvalidParams), "invalid end_time")
}
if startAt != nil && endAt != nil && !startAt.Before(*endAt) {
return errors.Wrapf(xerr.NewErrCode(xerr.InvalidParams), "start_time must be less than end_time")
}
switch ruleType {
@@ -93,12 +106,29 @@ func parseParams(data string) map[string]interface{} {
return params
}
func unixPtrToTimePtr(ts *int64) *time.Time {
func normalizeRuleTimestamp(ts *int64) (*time.Time, error) {
if ts == nil || *ts == 0 {
return nil, nil
}
value := *ts
var t time.Time
if value >= 1_000_000_000_000 || value <= -1_000_000_000_000 {
t = time.UnixMilli(value)
} else {
t = time.Unix(value, 0)
}
if t.Before(minPromoRuleTime) || t.After(maxPromoRuleTime) {
return nil, errors.Wrapf(xerr.NewErrCode(xerr.InvalidParams), "timestamp out of range")
}
return &t, nil
}
func unixPtrToTimePtr(ts *int64) *time.Time {
t, err := normalizeRuleTimestamp(ts)
if err != nil {
return nil
}
t := time.Unix(*ts, 0)
return &t
return t
}
func timePtrToUnixPtr(t *time.Time) *int64 {