🚸 调整展示时间 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

@@ -13,6 +13,7 @@ import (
"github.com/gin-contrib/pprof"
"github.com/gin-gonic/gin"
"github.com/naiba/nezha/model"
"github.com/naiba/nezha/pkg/mygin"
"github.com/naiba/nezha/service/singleton"
)
@@ -27,7 +28,7 @@ func ServeWeb(port uint) *http.Server {
r.Use(mygin.RecordPath)
r.SetFuncMap(template.FuncMap{
"tf": func(t time.Time) string {
return t.Format("2006年1月2号 15:04:05")
return t.In(model.Loc).Format("2006年1月2号 15:04:05")
},
"len": func(slice []interface{}) string {
return strconv.Itoa(len(slice))
@@ -39,7 +40,7 @@ func ServeWeb(port uint) *http.Server {
return template.HTML(`<` + s + `>`) // #nosec
},
"stf": func(s uint64) string {
return time.Unix(int64(s), 0).Format("2006年1月2号 15:04")
return time.Unix(int64(s), 0).In(model.Loc).Format("2006年1月2号 15:04")
},
"sf": func(duration uint64) string {
return time.Duration(time.Duration(duration) * time.Second).String()

View File

@@ -440,9 +440,24 @@ func (ma *memberAPI) addOrEditAlertRule(c *gin.Context) {
err = errors.New("至少定义一条规则")
} else {
for i := 0; i < len(r.Rules); i++ {
if !r.Rules[i].IsTransferDurationRule() && r.Rules[i].Duration < 3 {
err = errors.New("错误Duration 至少为 3")
break
if !r.Rules[i].IsTransferDurationRule() {
if r.Rules[i].Duration < 3 {
err = errors.New("错误Duration 至少为 3")
break
}
} else {
if r.Rules[i].CycleInterval < 1 {
err = errors.New("错误: cycle_interval 至少为 1")
break
}
if r.Rules[i].CycleStart == nil {
err = errors.New("错误: cycle_start 未设置")
break
}
if r.Rules[i].CycleStart.After(time.Now()) {
err = errors.New("错误: cycle_start 是个未来值")
break
}
}
}
}