From 15a72cda89dc67f1d441705885d5dea96f101aee Mon Sep 17 00:00:00 2001 From: Astrea <25420078+AstreaTSS@users.noreply.github.com> Date: Thu, 30 Nov 2023 11:36:54 -0500 Subject: [PATCH] fix: ensure next_fire in TimeTrigger returns proper next time (#1575) * fix: ensure time trigger target is greater than last call time * refactor: adjust fix to be more "proper" * docs: document the weird fix --- interactions/models/internal/tasks/triggers.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/interactions/models/internal/tasks/triggers.py b/interactions/models/internal/tasks/triggers.py index ab4bc89ae..1c1f3a13e 100644 --- a/interactions/models/internal/tasks/triggers.py +++ b/interactions/models/internal/tasks/triggers.py @@ -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)