mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 12:40:07 +00:00
🚸 调整展示时间 timezone
This commit is contained in:
@@ -6,6 +6,16 @@ const CtxKeyAuthorizedUser = "ckau"
|
||||
|
||||
const CacheKeyOauth2State = "p:a:state"
|
||||
|
||||
var Loc *time.Location
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
Loc, err = time.LoadLocation("Asia/Shanghai")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
type Common struct {
|
||||
ID uint64 `gorm:"primary_key"`
|
||||
CreatedAt time.Time `sql:"index"`
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user