fix(sleep): store sleep timestamps from GMT not Local (displayed +1h in BST)
Build and push images / validate (push) Successful in 3s
Build and push images / build-backend (push) Successful in 6s
Build and push images / build-worker (push) Successful in 4s
Build and push images / build-frontend (push) Successful in 5s

This commit is contained in:
2026-06-12 12:03:16 +01:00
parent b5b838bddc
commit 319b04e413
+9 -4
View File
@@ -555,10 +555,15 @@ def _parse_day(stats, sleep_data, hrv_data) -> dict:
_set(row, "sleep_rem_s", dto.get("remSleepSeconds"))
_set(row, "sleep_awake_s", dto.get("awakeSleepSeconds"))
# Timestamps are milliseconds since epoch in local time
for key, col in (("sleepStartTimestampLocal", "sleep_start"),
("sleepEndTimestampLocal", "sleep_end")):
ms = dto.get(key)
# Use the GMT timestamps (true epoch-ms instants). The *Local fields are
# the GMT value pre-shifted by the local UTC offset, so storing them as
# UTC and letting the frontend convert to local double-applies the offset
# (sleep displayed +1h in BST). GMT stored as UTC converts back correctly.
for gmt_key, local_key, col in (
("sleepStartTimestampGMT", "sleepStartTimestampLocal", "sleep_start"),
("sleepEndTimestampGMT", "sleepEndTimestampLocal", "sleep_end"),
):
ms = dto.get(gmt_key) or dto.get(local_key)
if ms:
_set(row, col, datetime.fromtimestamp(ms / 1000, tz=timezone.utc).isoformat())