Эх сурвалжийг харах

Fix timezone offset on parsed CalDAV datetimes

Convert tz-aware iCal datetimes to HA local time before extracting
date/time components, then strip tzinfo so values are stored as naive
local wall-clock times throughout.
ZiB 4 сар өмнө
parent
commit
68fef76144

+ 6 - 4
custom_components/room_cal_ha/coordinator.py

@@ -251,8 +251,9 @@ def _parse_event(event: caldav.Event) -> ReservationData | None:
       if not isinstance(dt, datetime):
         return None  # all-day event, not a reservation
 
-      check_in_date = dt.date()
-      check_in_time = dt.time()
+      dt_local = dt_util.as_local(dt) if dt.tzinfo is not None else dt
+      check_in_date = dt_local.date()
+      check_in_time = dt_local.time().replace(tzinfo=None)
       check_out_date = None
       check_out_time = None
 
@@ -260,8 +261,9 @@ def _parse_event(event: caldav.Event) -> ReservationData | None:
       if dtend is not None:
         dt_end = dtend.dt
         if isinstance(dt_end, datetime):
-          check_out_date = dt_end.date()
-          check_out_time = dt_end.time()
+          dt_end_local = dt_util.as_local(dt_end) if dt_end.tzinfo is not None else dt_end
+          check_out_date = dt_end_local.date()
+          check_out_time = dt_end_local.time().replace(tzinfo=None)
 
       x_data_prop = component.get(X_DATA_PROP)
       x_data_str = str(x_data_prop) if x_data_prop is not None else None