From f7b00fc7c4e42d36b4918c4b5f3f8af91a3328d6 Mon Sep 17 00:00:00 2001 From: Ryan Kegel Date: Fri, 17 Jul 2026 19:47:43 -0400 Subject: [PATCH] fix: adjust timezone handling for chore expiry notifications and ensure deadlines account for next occurrences --- backend/utils/chore_expiry_notification_scheduler.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/utils/chore_expiry_notification_scheduler.py b/backend/utils/chore_expiry_notification_scheduler.py index 8a3ce98..b3e88cb 100644 --- a/backend/utils/chore_expiry_notification_scheduler.py +++ b/backend/utils/chore_expiry_notification_scheduler.py @@ -62,7 +62,7 @@ def get_expiring_chores_for_user( try: from zoneinfo import ZoneInfo - local_now = datetime.now(ZoneInfo(tz_str)) if tz_str else now_dt + local_now = now_dt.astimezone(ZoneInfo(tz_str)) if tz_str else now_dt except Exception: local_now = now_dt @@ -106,10 +106,15 @@ def get_expiring_chores_for_user( continue # Anytime — no expiry due_hour, due_minute = due - # Build a timezone-aware deadline datetime for today + # Build a timezone-aware deadline datetime for the next occurrence of the due time. + # Schedules run hourly and may span midnight (e.g. a 23:00 run needs to catch + # a chore due at 00:15 the next day), so roll forward a day when the candidate + # deadline has already passed. deadline_dt = local_now.replace( hour=due_hour, minute=due_minute, second=0, microsecond=0 ) + if deadline_dt <= local_now: + deadline_dt = deadline_dt + timedelta(days=1) # Include only when deadline is strictly after now and within window if not (local_now < deadline_dt <= window_end):