From 852dd38add742d803bcba006e9f6f04552e401e4 Mon Sep 17 00:00:00 2001 From: Jacob Hagstedt Date: Wed, 3 Jun 2026 22:29:24 +0200 Subject: [PATCH] fix(stats): make API endpoints timezone-aware to fix sleep session attribution --- backend/app/routers/stats.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/backend/app/routers/stats.py b/backend/app/routers/stats.py index 73849f3..c427d68 100644 --- a/backend/app/routers/stats.py +++ b/backend/app/routers/stats.py @@ -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)