fix yesterdays schedule blocking todays

This commit is contained in:
Chelsea
2026-02-20 20:04:35 +00:00
parent fe07b3ebe7
commit 215c3d7f95
6 changed files with 4724 additions and 5 deletions

View File

@@ -468,6 +468,8 @@ def create_daily_schedule(user_uuid: str, med_id: str, base_times: List[str], re
# Check recent med logs to skip doses already taken/skipped.
# Handles cross-midnight: if adaptive offset shifts 23:00 → 00:42 today,
# but the user already took the 23:00 dose last night, don't schedule it.
# Yesterday's logs only suppress if the scheduled_time is late-night
# (21:00+), since only those could plausibly cross midnight with an offset.
user_tz = tz_for_user(user_uuid)
yesterday = today - timedelta(days=1)
recent_logs = postgres.select("med_logs", {"medication_id": med_id, "user_uuid": user_uuid})
@@ -481,11 +483,15 @@ def create_daily_schedule(user_uuid: str, med_id: str, base_times: List[str], re
if created_at.tzinfo is None:
created_at = created_at.replace(tzinfo=timezone.utc)
log_date = created_at.astimezone(user_tz).date()
if log_date not in (today, yesterday):
continue
log_sched = _normalize_time(log.get("scheduled_time"))
if log_sched:
taken_base_times.add(log_sched)
if log_date == today:
log_sched = _normalize_time(log.get("scheduled_time"))
if log_sched:
taken_base_times.add(log_sched)
elif log_date == yesterday:
# Only suppress cross-midnight doses (late-night times like 21:00+)
log_sched = _normalize_time(log.get("scheduled_time"))
if log_sched and log_sched >= "21:00":
taken_base_times.add(log_sched)
# Create schedule records for each time
for base_time, (adjusted_time, offset) in zip(base_times, adjusted_times):