Repository: allenporter/gcal_sync (language: python)

Issue:
Add sync timezone tests
Add more complex tests with respect to timezone handling and interpretation.


Discussion / hints:

Fix patch:
diff --git a/gcal_sync/api.py b/gcal_sync/api.py
index 655e160..9cf71a4 100644
--- a/gcal_sync/api.py
+++ b/gcal_sync/api.py
@@ -460,7 +460,9 @@ async def async_list_events(
             )
         )
 
-    async def async_get_timeline(self) -> Timeline:
+    async def async_get_timeline(
+        self, tzinfo: datetime.tzinfo | None = None
+    ) -> Timeline:
         """Get the timeline of events."""
         store_data = await self._store.async_load() or {}
         store_data.setdefault(ITEMS, {})
@@ -474,4 +476,4 @@ async def async_get_timeline(self) -> Timeline:
                 continue
             events.append(event)
 
-        return calendar_timeline(events)
+        return calendar_timeline(events, tzinfo if tzinfo else datetime.timezone.utc)
diff --git a/gcal_sync/timeline.py b/gcal_sync/timeline.py
index f02de73..2b6fa7b 100644
--- a/gcal_sync/timeline.py
+++ b/gcal_sync/timeline.py
@@ -9,15 +9,12 @@
 
 import datetime
 import heapq
-import logging
 from collections.abc import Iterable, Iterator
 
 from .iter import MergedIterable, RecurIterable
 from .model import DateOrDatetime, Event
 from .timespan import Timespan
 
-_LOGGER = logging.getLogger(__name__)
-
 __all__ = ["Timeline"]
 
 


Test patch:
diff --git a/tests/test_sync.py b/tests/test_sync.py
index b425436..87140c9 100644
--- a/tests/test_sync.py
+++ b/tests/test_sync.py
@@ -3,6 +3,7 @@
 from __future__ import annotations
 
 import datetime
+import zoneinfo
 from collections.abc import Awaitable, Callable
 from unittest.mock import patch
 
@@ -678,10 +679,10 @@ async def test_canceled_events(
                     "summary": "Event 3",
                     "description": "Event description 3",
                     "start": {
-                        "date": "2022-04-15",
+                        "date": "2022-04-21",
                     },
                     "end": {
-                        "date": "2022-04-20",
+                        "date": "2022-04-22",
                     },
                 },
             ],
@@ -706,11 +707,35 @@ async def test_canceled_events(
             id="some-event-id-3",
             summary="Event 3",
             description="Event description 3",
-            start=DateOrDatetime(date=datetime.date(2022, 4, 15)),
-            end=DateOrDatetime(date=datetime.date(2022, 4, 20)),
+            start=DateOrDatetime(date=datetime.date(2022, 4, 21)),
+            end=DateOrDatetime(date=datetime.date(2022, 4, 22)),
         ),
     ]
 
+    # Exercise the timeline and dependencies on the timezone
+    timeline = await sync.store_service.async_get_timeline(
+        zoneinfo.ZoneInfo("America/Regina")
+    )
+    assert [event.summary for event in timeline] == ["Event 2", "Event 3"]
+
+    event_iter = timeline.start_after(
+        DateOrDatetime.parse(
+            datetime.datetime(
+                2022, 4, 20, 23, 0, 0, tzinfo=zoneinfo.ZoneInfo("America/Regina")
+            )
+        )
+    )
+    assert [event.summary for event in event_iter] == ["Event 3"]
+
+    event_iter = timeline.start_after(
+        DateOrDatetime.parse(
+            datetime.datetime(
+                2022, 4, 21, 1, 0, 0, tzinfo=zoneinfo.ZoneInfo("America/Regina")
+            )
+        )
+    )
+    assert [event.summary for event in event_iter] == []
+
 
 async def test_event_sync_recover_failure(
     calendar_list_sync_manager_cb: Callable[[], Awaitable[CalendarListSyncManager]],