Skip to content

Commit

Permalink
fix: 统一时区获取方法 (1Panel-dev#6175)
Browse files Browse the repository at this point in the history
  • Loading branch information
ssongliu authored Aug 19, 2024
1 parent a9c7a5c commit c78ca69
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 24 deletions.
2 changes: 1 addition & 1 deletion backend/app/api/v1/cronjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func (b *BaseApi) SearchJobRecords(c *gin.Context) {
return
}

loc, _ := time.LoadLocation(common.LoadTimeZone())
loc, _ := time.LoadLocation(common.LoadTimeZoneByCmd())
req.StartTime = req.StartTime.In(loc)
req.EndTime = req.EndTime.In(loc)

Expand Down
2 changes: 1 addition & 1 deletion backend/app/api/v1/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (b *BaseApi) LoadMonitor(c *gin.Context) {
return
}

loc, _ := time.LoadLocation(common.LoadTimeZone())
loc, _ := time.LoadLocation(common.LoadTimeZoneByCmd())
req.StartTime = req.StartTime.In(loc)
req.EndTime = req.EndTime.In(loc)

Expand Down
2 changes: 1 addition & 1 deletion backend/app/repo/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func (u *BackupRepo) ListRecord(opts ...DBOption) ([]model.BackupRecord, error)
for _, opt := range opts {
db = opt(db)
}
err := db.Debug().Find(&users).Error
err := db.Find(&users).Error
return users, err
}

Expand Down
4 changes: 2 additions & 2 deletions backend/app/service/clam.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ func (c *ClamService) SearchWithPage(req dto.SearchClamWithPage) (int64, interfa
item.LastHandleDate = "-"
datas = append(datas, item)
}
nyc, _ := time.LoadLocation(common.LoadTimeZone())
nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd())
for i := 0; i < len(datas); i++ {
logPaths := loadFileByName(datas[i].Name)
sort.Slice(logPaths, func(i, j int) bool {
Expand Down Expand Up @@ -323,7 +323,7 @@ func (c *ClamService) LoadRecords(req dto.ClamLogSearch) (int64, interface{}, er
}

var filterFiles []string
nyc, _ := time.LoadLocation(common.LoadTimeZone())
nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd())
for _, item := range logPaths {
t1, err := time.ParseInLocation(constant.DateTimeSlimLayout, item, nyc)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion backend/app/service/container_volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (u *ContainerService) PageVolume(req dto.SearchWithPage) (int64, interface{
records = list.Volumes[start:end]
}

nyc, _ := time.LoadLocation(common.LoadTimeZone())
nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd())
for _, item := range records {
tag := make([]string, 0)
for _, val := range item.Labels {
Expand Down
2 changes: 1 addition & 1 deletion backend/app/service/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ func (u *SSHService) LoadLog(req dto.SearchSSHLog) (*dto.SSHLog, error) {

showCountFrom := (req.Page - 1) * req.PageSize
showCountTo := req.Page * req.PageSize
nyc, _ := time.LoadLocation(common.LoadTimeZone())
nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd())
qqWry, err := qqwry.NewQQwry()
if err != nil {
global.LOG.Errorf("load qqwry datas failed: %s", err)
Expand Down
4 changes: 2 additions & 2 deletions backend/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ import (
)

func Run() {
nyc, _ := time.LoadLocation(common.LoadTimeZone())
nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd())
global.Cron = cron.New(cron.WithLocation(nyc), cron.WithChain(cron.Recover(cron.DefaultLogger)), cron.WithChain(cron.DelayIfStillRunning(cron.DefaultLogger)))

var (
interval model.Setting
status model.Setting
)
syncBeforeStart()
go syncBeforeStart()
if err := global.DB.Where("key = ?", "MonitorStatus").Find(&status).Error; err != nil {
global.LOG.Errorf("load monitor status from db failed, err: %v", err)
}
Expand Down
9 changes: 5 additions & 4 deletions backend/cron/job/ssl.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package job

import (
"path"
"strings"
"time"

"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/backend/app/service"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/common"
"github.com/1Panel-dev/1Panel/backend/utils/files"
"path"
"strings"
"time"
)

type ssl struct {
Expand All @@ -25,7 +26,7 @@ func (ssl *ssl) Run() {
sslRepo := repo.NewISSLRepo()
sslService := service.NewIWebsiteSSLService()
sslList, _ := sslRepo.List()
nyc, _ := time.LoadLocation(common.LoadTimeZone())
nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd())
global.LOG.Info("The scheduled certificate update task is currently in progress ...")
now := time.Now().Add(10 * time.Second)
for _, s := range sslList {
Expand Down
7 changes: 4 additions & 3 deletions backend/cron/job/website.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package job

import (
"sync"
"time"

"github.com/1Panel-dev/1Panel/backend/app/dto/request"
"github.com/1Panel-dev/1Panel/backend/app/model"
"github.com/1Panel-dev/1Panel/backend/app/repo"
"github.com/1Panel-dev/1Panel/backend/app/service"
"github.com/1Panel-dev/1Panel/backend/constant"
"github.com/1Panel-dev/1Panel/backend/global"
"github.com/1Panel-dev/1Panel/backend/utils/common"
"sync"
"time"
)

type website struct{}
Expand All @@ -19,7 +20,7 @@ func NewWebsiteJob() *website {
}

func (w *website) Run() {
nyc, _ := time.LoadLocation(common.LoadTimeZone())
nyc, _ := time.LoadLocation(common.LoadTimeZoneByCmd())
websites, _ := repo.NewIWebsiteRepo().List()
global.LOG.Info("Website scheduled task in progress ...")
now := time.Now().Add(10 * time.Minute)
Expand Down
2 changes: 1 addition & 1 deletion backend/middleware/password_expired.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func PasswordExpired() gin.HandlerFunc {
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypePasswordExpired, err)
return
}
loc, _ := time.LoadLocation(common.LoadTimeZone())
loc, _ := time.LoadLocation(common.LoadTimeZoneByCmd())
expiredTime, err := time.ParseInLocation(constant.DateTimeLayout, extime.Value, loc)
if err != nil {
helper.ErrorWithDetail(c, constant.CodePasswordExpired, constant.ErrTypePasswordExpired, err)
Expand Down
7 changes: 0 additions & 7 deletions backend/utils/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,13 +256,6 @@ func LoadSizeUnit2F(value float64) string {
return fmt.Sprintf("%.2f", value)
}

func LoadTimeZone() string {
loc := time.Now().Location()
if _, err := time.LoadLocation(loc.String()); err != nil {
return "Asia/Shanghai"
}
return loc.String()
}
func LoadTimeZoneByCmd() string {
loc := time.Now().Location().String()
if _, err := time.LoadLocation(loc); err != nil {
Expand Down
2 changes: 2 additions & 0 deletions frontend/src/views/toolbox/device/time-zone/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ const onSave = async (formEl: FormInstance | undefined) => {
})
.catch(() => {
loading.value = false;
let href = window.location.href;
window.open(href, '_self');
});
});
});
Expand Down

0 comments on commit c78ca69

Please sign in to comment.