fix: BUG-06 — convert naive Pi timestamps to TZ-aware before upload so Postgres TIMESTAMPTZ stores correct instant

This commit is contained in:
Mathieu Moran
2026-08-11 14:47:37 -04:00
parent 9733036510
commit 7ce2a1e5f5
3 changed files with 39 additions and 9 deletions
+11 -6
View File
@@ -28,15 +28,20 @@ When CLOSED, move the entire entry to Resolved — don't duplicate.
---
### BUG-06 — Server timestamps are shifted (naive local time stored as UTC)
- **Status**: `OPEN`
- **Status**: `IN PROGRESS` (fix deployed 2026-08-11, needs new-data verification)
- **Severity**: High-ish
- **Area**: `modules/app_upload.py`, `server/sql`, `server/modules/db.py`, portal
- **Phase**: Phase 26
- **Symptom**: Server trip times shifted by EDT offset (~4-5h).
- **Root cause**: Pi sends naive local time; Postgres `TIMESTAMPTZ` interprets as UTC.
- **Fix scope**: Pi sends timezone-aware timestamps. Server stores/reads consistently.
One-time migration for existing rows — **get owner sign-off**.
- **Acceptance**: New data at correct local time; existing rows corrected or accepted.
- **Symptom**: Server trip times shifted by EDT offset (~4-5h). Pi stores naive
local time; Postgres `TIMESTAMPTZ` interprets it as UTC.
- **Fix**: New `_to_tz_aware()` helper in `app_upload.py` converts naive SQLite
timestamps to timezone-aware ISO strings before upload (e.g.,
`2026-08-10 19:27:30` → `2026-08-10T19:27:30-04:00`). Already-aware timestamps
pass through unchanged. **Existing rows on the server are NOT migrated** — only
new uploads benefit from this fix. Old trips will still show the wrong time
until a one-time server-side `UPDATE` migration is run (needs owner sign-off).
- **Acceptance**: New trips uploaded after this fix display correct local time
on both portal and Pi.
---