fix(stats): make API endpoints timezone-aware to fix sleep session attribution

This commit is contained in:
2026-06-03 22:29:24 +02:00
parent 7ff1c22edc
commit 852dd38add
+10 -1
View File
@@ -19,6 +19,9 @@ async def get_daily_summary(
timezone_offset: int = Query(0),
session: AsyncSession = Depends(get_session),
):
if to_date.hour == 0 and to_date.minute == 0:
to_date = to_date.replace(hour=23, minute=59, second=59, microsecond=999999)
try:
day_start_time = time.fromisoformat(day_start)
day_end_time = time.fromisoformat(day_end)
@@ -74,6 +77,9 @@ async def get_timetable(
timezone_offset: int = Query(0),
session: AsyncSession = Depends(get_session),
):
if to_date.hour == 0 and to_date.minute == 0:
to_date = to_date.replace(hour=23, minute=59, second=59, microsecond=999999)
utc_from_date = from_date + timedelta(minutes=timezone_offset)
utc_to_date = to_date + timedelta(minutes=timezone_offset)
adj_utc_from_date = utc_from_date - timedelta(days=1)
@@ -156,12 +162,15 @@ async def get_wake_sleep_times(
timezone_offset: int = Query(0),
session: AsyncSession = Depends(get_session),
):
if to_date.hour == 0 and to_date.minute == 0:
to_date = to_date.replace(hour=23, minute=59, second=59, microsecond=999999)
try:
w_ref_time = time.fromisoformat(wakeup_ref)
b_ref_time = time.fromisoformat(bedtime_ref)
except ValueError:
return {"days": []}
utc_from_date = from_date + timedelta(minutes=timezone_offset)
utc_to_date = to_date + timedelta(minutes=timezone_offset)
adj_utc_from_date = utc_from_date - timedelta(days=1)