From da376a8b182e2ad71e07984320e412dd0ffcf8e7 Mon Sep 17 00:00:00 2001 From: Lars Date: Sun, 22 Mar 2026 12:57:20 +0100 Subject: [PATCH] feat: store full datetime in sleep_segments JSONB Enhanced sleep_segments data structure: - start: ISO datetime (2026-03-21T22:30:00) instead of HH:MM - end: ISO datetime (2026-03-21T23:15:00) - NEW - phase: sleep phase type - duration_min: duration in minutes Benefits: - Exact timestamp for each segment (no date ambiguity) - Can reconstruct complete sleep timeline - Enables precise cycle analysis - Handles midnight crossings correctly Example: [ {"phase": "light", "start": "2026-03-21T22:30:00", "end": "2026-03-21T23:15:00", "duration_min": 45}, {"phase": "deep", "start": "2026-03-21T23:15:00", "end": "2026-03-22T00:30:00", "duration_min": 75} ] Co-Authored-By: Claude Opus 4.6 --- backend/routers/sleep.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/backend/routers/sleep.py b/backend/routers/sleep.py index ec8f056..4dd9a1a 100644 --- a/backend/routers/sleep.py +++ b/backend/routers/sleep.py @@ -545,11 +545,12 @@ async def import_apple_health_sleep( night['awake_minutes'] ) - # Prepare JSONB segments + # Prepare JSONB segments with full datetime sleep_segments = [ { 'phase': seg['phase'], - 'start': seg['start'].strftime('%H:%M'), + 'start': seg['start'].isoformat(), # Full datetime: 2026-03-21T22:30:00 + 'end': seg['end'].isoformat(), # Full datetime: 2026-03-21T23:15:00 'duration_min': seg['duration_min'] } for seg in night['segments']