Skip to content

Commit

Permalink
fix: incorrect current time when applying timezone offsets (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
nekomeowww authored May 23, 2023
1 parent 37cded6 commit 33b31d8
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions internal/models/tgchats/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,16 @@ func (m *Model) QueueOneSendChatHistoriesRecapTaskForChatID(chatID int64) error
ctx, cancel := context.WithTimeout(context.Background(), time.Second*5)
defer cancel()

now := time.Now()

location := time.UTC
if m.config.TimezoneShiftSeconds > 0 {
if m.config.TimezoneShiftSeconds != 0 {
location = time.FixedZone("Local", int(m.config.TimezoneShiftSeconds))
}

now := time.
Now(). // Current time.
UTC(). // Resets to UTC.
In(location) // Align current timezone with the configured offset (if any) for later calculation.

scheduleTargets := []int64{2, 8, 14, 20} // queue for 02:00, 08:00, 14:00, 20:00
scheduleSets := make([]time.Time, 0, len(scheduleTargets))

Expand Down

0 comments on commit 33b31d8

Please sign in to comment.