Skip to content

Commit

Permalink
fix: ensure next_fire in TimeTrigger returns proper next time (#1575)
Browse files Browse the repository at this point in the history
* fix: ensure time trigger target is greater than last call time

* refactor: adjust fix to be more "proper"

* docs: document the weird fix
  • Loading branch information
AstreaTSS authored Nov 30, 2023
1 parent f049570 commit 15a72cd
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion interactions/models/internal/tasks/triggers.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,11 @@ def next_fire(self) -> datetime | None:
)
if target.tzinfo == timezone.utc:
target = target.astimezone(now.tzinfo)
target = target.replace(tzinfo=None)
# target can fall behind or go forward a day, but all we need is the time itself
# to be converted
# to ensure it's on the same day as "now" and not break the next if statement,
# we can just replace the date with now's date
target = target.replace(year=now.year, month=now.month, day=now.day, tzinfo=None)

if target <= self.last_call_time:
target += timedelta(days=1)
Expand Down

0 comments on commit 15a72cd

Please sign in to comment.