🚸 调整展示时间 timezone

This commit is contained in:
naiba
2022-03-01 10:19:23 +08:00
parent 520f8d2170
commit d60bc3dad6
8 changed files with 62 additions and 37 deletions

View File

@@ -23,9 +23,9 @@ type Rule struct {
Type string `json:"type,omitempty"`
Min float64 `json:"min,omitempty"` // 最小阈值 (百分比、字节 kb ÷ 1024)
Max float64 `json:"max,omitempty"` // 最大阈值 (百分比、字节 kb ÷ 1024)
CycleStart time.Time `json:"cycle_start,omitempty"` // 流量统计的开始时间
CycleStart *time.Time `json:"cycle_start,omitempty"` // 流量统计的开始时间
CycleInterval uint64 `json:"cycle_interval,omitempty"` // 流量统计周期
CycleUnit string `json:"cycle_unit,omitempty"` // 流量统计周期单位默认hour,可选(hour, day, week, month, year)
CycleUnit string `json:"cycle_unit,omitempty"` // 流量统计周期单位默认hour,可选(hour, day, week, month, year)
Duration uint64 `json:"duration,omitempty"` // 持续时间 (秒)
Cover uint64 `json:"cover,omitempty"` // 覆盖范围 RuleCoverAll/IgnoreAll
Ignore map[uint64]bool `json:"ignore,omitempty"` // 覆盖范围的排除
@@ -166,7 +166,7 @@ func (rule Rule) IsTransferDurationRule() bool {
func (rule Rule) GetTransferDurationStart() time.Time {
// Accept uppercase and lowercase
unit := strings.ToLower(rule.CycleUnit)
startTime := rule.CycleStart
startTime := *rule.CycleStart
var nextTime time.Time
switch unit {
case "year":
@@ -182,10 +182,10 @@ func (rule Rule) GetTransferDurationStart() time.Time {
nextTime = nextTime.AddDate(0, int(rule.CycleInterval), 0)
}
case "week":
nextTime = startTime.AddDate(0, 0, 7 * int(rule.CycleInterval))
nextTime = startTime.AddDate(0, 0, 7*int(rule.CycleInterval))
for time.Now().After(nextTime) {
startTime = nextTime
nextTime = nextTime.AddDate(0, 0, 7 * int(rule.CycleInterval))
nextTime = nextTime.AddDate(0, 0, 7*int(rule.CycleInterval))
}
case "day":
nextTime = startTime.AddDate(0, 0, int(rule.CycleInterval))
@@ -205,7 +205,7 @@ func (rule Rule) GetTransferDurationStart() time.Time {
func (rule Rule) GetTransferDurationEnd() time.Time {
// Accept uppercase and lowercase
unit := strings.ToLower(rule.CycleUnit)
startTime := rule.CycleStart
startTime := *rule.CycleStart
var nextTime time.Time
switch unit {
case "year":
@@ -221,10 +221,10 @@ func (rule Rule) GetTransferDurationEnd() time.Time {
nextTime = nextTime.AddDate(0, int(rule.CycleInterval), 0)
}
case "week":
nextTime = startTime.AddDate(0, 0, 7 * int(rule.CycleInterval))
nextTime = startTime.AddDate(0, 0, 7*int(rule.CycleInterval))
for time.Now().After(nextTime) {
startTime = nextTime
nextTime = nextTime.AddDate(0, 0, 7 * int(rule.CycleInterval))
nextTime = nextTime.AddDate(0, 0, 7*int(rule.CycleInterval))
}
case "day":
nextTime = startTime.AddDate(0, 0, int(rule.CycleInterval))
@@ -236,7 +236,7 @@ func (rule Rule) GetTransferDurationEnd() time.Time {
// For hour unit or not set.
interval := 3600 * int64(rule.CycleInterval)
startTime = time.Unix(rule.CycleStart.Unix()+(time.Now().Unix()-rule.CycleStart.Unix())/interval*interval, 0)
nextTime = time.Unix(startTime.Unix() + interval, 0)
nextTime = time.Unix(startTime.Unix()+interval, 0)
}
return nextTime