Skip to content

Commit

Permalink
fix:timestamp bug (#95)
Browse files Browse the repository at this point in the history
  • Loading branch information
FantasyRL authored Nov 11, 2024
1 parent 6f12be8 commit 596e483
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
5 changes: 2 additions & 3 deletions internal/launch_screen/service/create_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"golang.org/x/sync/errgroup"

"github.com/west2-online/fzuhelper-server/kitex_gen/launch_screen"
"github.com/west2-online/fzuhelper-server/pkg/constants"
"github.com/west2-online/fzuhelper-server/pkg/db/model"
"github.com/west2-online/fzuhelper-server/pkg/upyun"
)
Expand Down Expand Up @@ -51,8 +50,8 @@ func (s *LaunchScreenService) CreateImage(req *launch_screen.CreateImageRequest)
StartTime: req.StartTime,
EndTime: req.EndTime,
Regex: req.Regex,
StartAt: time.Unix(req.StartAt, 0).Add(constants.TimeZoneOffset * time.Hour),
EndAt: time.Unix(req.EndAt, 0).Add(constants.TimeZoneOffset * time.Hour),
StartAt: time.Unix(req.StartAt, 0),
EndAt: time.Unix(req.EndAt, 0),
}
pic, err = s.db.LaunchScreen.CreateImage(s.ctx, pictureModel)
return err
Expand Down
5 changes: 2 additions & 3 deletions internal/launch_screen/service/update_image_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"time"

"github.com/west2-online/fzuhelper-server/kitex_gen/launch_screen"
"github.com/west2-online/fzuhelper-server/pkg/constants"
"github.com/west2-online/fzuhelper-server/pkg/db/model"
)

Expand All @@ -36,8 +35,8 @@ func (s *LaunchScreenService) UpdateImageProperty(req *launch_screen.ChangeImage
origin.Href = *req.Href
origin.Frequency = req.Frequency
origin.Text = req.Text
origin.StartAt = time.Unix(req.StartAt, 0).Add(constants.TimeZoneOffset * time.Hour)
origin.EndAt = time.Unix(req.EndAt, 0).Add(constants.TimeZoneOffset * time.Hour)
origin.StartAt = time.Unix(req.StartAt, 0)
origin.EndAt = time.Unix(req.EndAt, 0)
origin.StartTime = req.StartTime
origin.EndTime = req.EndTime
origin.Regex = req.Regex
Expand Down
11 changes: 4 additions & 7 deletions pkg/db/launch_screen/get_image.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import (
"fmt"
"time"

"github.com/west2-online/fzuhelper-server/pkg/constants"
"github.com/west2-online/fzuhelper-server/pkg/db/model"
"github.com/west2-online/fzuhelper-server/pkg/utils"
)
Expand All @@ -39,7 +38,7 @@ func (c *DBLaunchScreen) GetImageBySType(ctx context.Context, sType int64) (*[]m
pictures := new([]model.Picture)
var count int64 = 0
now := time.Now().In(Loc)
hour := now.In(Loc).Hour()
hour := now.Hour()
// 按创建时间降序
if err := c.client.WithContext(ctx).
Where("s_type = ? AND start_at < ? AND end_at > ? AND start_time <= ? AND end_time >= ?",
Expand All @@ -53,13 +52,11 @@ func (c *DBLaunchScreen) GetImageBySType(ctx context.Context, sType int64) (*[]m
}

func (c *DBLaunchScreen) GetImageByIdList(ctx context.Context, imgIdList *[]int64) (*[]model.Picture, int64, error) {
Loc := utils.LoadCNLocation()
pictures := new([]model.Picture)
var count int64 = 0
now := time.Now().Add(time.Hour * constants.TimeZoneOffset)
hour := now.Hour() + constants.TimeZoneOffset
if hour > constants.DayTime {
hour -= constants.DayTime
}
now := time.Now().In(Loc)
hour := now.Hour()
err := c.client.WithContext(ctx).
Where("id IN ? AND start_at < ? AND end_at > ? AND start_time <= ? AND end_time >= ?",
*imgIdList, now, now, hour, hour).Count(&count).Order("created_at DESC").Find(pictures).Error
Expand Down

0 comments on commit 596e483

Please sign in to comment.