fix yesterdays schedule blocking todays
This commit is contained in:
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user