Files
junhong_cmp_fiber/internal/domain/carrierthreshold/period.go
break 59b3df868a
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 12m59s
feat(通道流量阈值): AUG26-011 运营商通道流量阈值达量停机与周期复机
2026-09-16 15:54:49 +08:00

30 lines
1.2 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package carrierthreshold
import (
"time"
"github.com/break/junhong_cmp_fiber/pkg/errors"
)
// shanghaiLocation 是计费周期边界的固定时区。
// 中国自 1991 年起不实行夏令时,使用固定偏移可避免依赖宿主机 tzdata。
var shanghaiLocation = time.FixedZone("Asia/Shanghai", 8*60*60)
// PeriodStart 计算 now 所属计费周期的起点(上海时区零点)。
//
// 周期起点 = 本月重置日 0 点,若 now 早于本月重置日 0 点则取上月重置日 0 点。
// resetDay 由该卡所属运营商(锁行自身的 carrier的 data_reset_day 提供,合法范围 1-28
// 因此每个月都有定义。该口径与 isTrafficResetWindow判断读数回落是否为合法清零的观测窗口
// 是两个独立口径,互不修改。
func PeriodStart(now time.Time, resetDay int) (time.Time, error) {
if resetDay < MinResetDay || resetDay > MaxResetDay {
return time.Time{}, errors.New(errors.CodeInvalidParam, "运营商上游流量重置日必须在 1-28 之间")
}
local := now.In(shanghaiLocation)
current := time.Date(local.Year(), local.Month(), resetDay, 0, 0, 0, 0, shanghaiLocation)
if !local.Before(current) {
return current, nil
}
return current.AddDate(0, -1, 0), nil
}