Soon fixing timeone in wakeup plot

This commit is contained in:
2026-05-27 17:58:22 +02:00
parent 3e8a2092cd
commit fb709b4a2c
8 changed files with 340 additions and 45 deletions
+9 -13
View File
@@ -1,17 +1,13 @@
# Plan: Fix Timezone issues in WakeupPlot
# Plan: Fix Wakeup Plot Timezone Display
## Status: COMPLETED
## Problem
`WakeupPlot.tsx` uses an incorrect manual calculation for timezone offsets and a dubious `isLikelyOffset` heuristic. This causes incorrect time displays (e.g., subtracting the offset instead of adding it).
`WakeupPlot.tsx` shows incorrect wakeup times (e.g., showing 01:00 instead of 05:00 when input is 03:00 UTC in Stockholm). This was caused by sending a local reference time to the backend, which then calculated a delta relative to that time being treated as UTC.
## Goal
Align `WakeupPlot.tsx` with `BedtimePlot.tsx` by using the existing `getLocalOffsetFromReference` utility to correctly apply client-side timezone adjustments.
## Solution
1. **Frontend API Fix**: Modified `fetchWakeSleepTimes` in `frontend/src/api/client.ts` to convert the local `wakeup_ref` and `bedtime_ref` HH:MM strings into UTC HH:MM strings before sending them to the backend.
2. **Frontend Component Fix**: Updated `WakeupPlot.tsx` and `BedtimePlot.tsx` to use the returned `wakeup_minutes`/`bedtime_minutes` (which is now a correctly calculated timezone-invariant delta) directly as the offset from reference, instead of attempting to re-adjust it using local timezone offsets.
## Steps
1. **Modify `frontend/src/components/stats/WakeupPlot.tsx`**:
- Remove the `isLikelyOffset` logic and manual offset calculations.
- Use `getLocalOffsetFromReference(day.wakeup_minutes, wakeup_ref)` to calculate the correct local offset.
2. **Verify**:
- Ensure the component renders correctly with the new logic.
## Files to change
- `frontend/src/components/stats/WakeupPlot.tsx`
## Verification
Verified with Playwright test in `Europe/Stockholm` timezone: 03:00 UTC input correctly displays as 05:00.