mirror of
https://github.com/HKUDS/DeepTutor.git
synced 2026-12-02 17:40:18 +08:00
fix(calendar): preserve repeated-hour instants in ICS exports (#2782)
This commit is contained in:
committed by
GitHub
parent
9744bad61b
commit
4ef7820b60
@@ -1,7 +1,8 @@
|
||||
"""Render stored calendar events as RFC 5545 iCalendar text.
|
||||
|
||||
Timed events use local wall time with ``TZID`` and a ``VTIMEZONE`` per used
|
||||
zone. Offsets come from ``zoneinfo`` transitions in a window covering the
|
||||
zone. A non-recurring event that uses the second occurrence of a repeated
|
||||
wall time is written in UTC to preserve the intended instant. Offsets come from ``zoneinfo`` transitions in a window covering the
|
||||
exported events (padded by a year; spans over 40 years are rejected). UTC timed events use
|
||||
the ``Z`` form and skip ``VTIMEZONE``. All-day events use ``VALUE=DATE`` with
|
||||
the store's exclusive end date.
|
||||
@@ -165,10 +166,12 @@ def _dtstart_dtend(event: CalendarEvent) -> list[str]:
|
||||
_prop("DTSTART", _ics_date(timing.dtstart), VALUE="DATE"),
|
||||
_prop("DTEND", _ics_date(timing.dtend), VALUE="DATE"),
|
||||
]
|
||||
if event.tzid == "UTC":
|
||||
# RFC 5545 local times in a repeated hour always select the first
|
||||
# occurrence. UTC preserves both endpoints without changing a repeat rule.
|
||||
if event.tzid == "UTC" or (not event.rrule and (timing.start_fold or timing.end_fold)):
|
||||
return [
|
||||
_prop("DTSTART", f"{_ics_datetime(timing.dtstart)}Z"),
|
||||
_prop("DTEND", f"{_ics_datetime(timing.dtend)}Z"),
|
||||
_prop("DTSTART", _stamp(event.start)),
|
||||
_prop("DTEND", _stamp(event.end)),
|
||||
]
|
||||
return [
|
||||
_prop("DTSTART", _ics_datetime(timing.dtstart), TZID=event.tzid),
|
||||
|
||||
@@ -277,3 +277,19 @@ def test_all_day_events_do_not_widen_the_timezone_window(store):
|
||||
onsets = [line.split(":", 1)[1] for line in zone_lines if line.startswith("DTSTART:")]
|
||||
assert min(onsets) >= "2025"
|
||||
assert "20260329T020000" in onsets
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("start", "end", "ics_start", "ics_end"),
|
||||
[
|
||||
("2026-11-01T06:30:00Z", "2026-11-01T07:00:00Z", "20261101T063000Z", "20261101T070000Z"),
|
||||
("2026-11-01T05:30:00Z", "2026-11-01T06:30:00Z", "20261101T053000Z", "20261101T063000Z"),
|
||||
],
|
||||
)
|
||||
def test_single_event_export_preserves_the_second_occurrence_of_a_wall_time(
|
||||
store, start, end, ics_start, ics_end
|
||||
):
|
||||
create(store, tzid="America/New_York", start=start, end=end)
|
||||
block = vevents(ics(store))[0]
|
||||
assert block["DTSTART"] == [ics_start]
|
||||
assert block["DTEND"] == [ics_end]
|
||||
|
||||
Reference in New Issue
Block a user