Skip to content

Commit c3621e8

Browse files
Merge pull request #45 from pycalendar/fix/tzid-normalization
fix(convert): normalize non-IANA TZID to an IANA name in timeZone
2 parents 7a8aef2 + 344022c commit c3621e8

3 files changed

Lines changed: 45 additions & 4 deletions

File tree

‎news/44.bugfix.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
``ical_to_jscal`` now normalizes non-IANA ``TZID`` values (Windows timezone names, vendor-prefixed globally-unique TZIDs) to IANA names in ``timeZone``, as RFC 8984 requires, instead of passing them through unchanged.

‎src/calendaring_jmap/convert/ical_to_jscal.py‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from datetime import date, datetime, timedelta
1818

1919
import icalendar
20+
from icalendar.timezone.tzid import tzid_from_dt
2021

2122
from calendaring_jmap.convert._fixup import fixup
2223
from calendaring_jmap.convert._utils import _format_local_dt, _timedelta_to_duration
@@ -93,10 +94,10 @@ def _dtstart_to_jscal(dtstart_prop) -> tuple[str, str | None, bool]:
9394
return dt.strftime("%Y-%m-%dT%H:%M:%S"), "Etc/UTC", False
9495

9596
if dt.tzinfo is not None:
96-
# Timezone-aware — prefer the TZID parameter (IANA name) over tzinfo repr
97-
# NOTE: non-IANA TZIDs (e.g. "Eastern Standard Time" from Outlook)
98-
# are passed through unchanged; mapping to IANA is out of scope.
99-
tz_str = dtstart_prop.params.get("TZID")
97+
# Timezone-aware. RFC 8984 requires an IANA name; a raw TZID param
98+
# can be a Windows or vendor-prefixed name instead, so resolve via
99+
# tzid_from_dt() rather than using the param string directly.
100+
tz_str = tzid_from_dt(dt)
100101
return dt.strftime("%Y-%m-%dT%H:%M:%S"), tz_str, False
101102

102103
# Floating (no timezone)

‎src/calendaring_jmap/tests/test_jmap_unit.py‎

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1701,6 +1701,45 @@ def test_timezone_aware_event(self):
17011701
assert result["timeZone"] == "America/New_York"
17021702
assert "showWithoutTime" not in result
17031703

1704+
def test_windows_tzid_is_normalized_to_iana(self):
1705+
"""Outlook emits Windows timezone names; RFC 8984 requires an IANA
1706+
name in timeZone, so the raw TZID param must be resolved, not
1707+
passed through."""
1708+
ical = _make_ical(
1709+
"DTSTART;TZID=Eastern Standard Time:20240615T100000\r\n"
1710+
"DURATION:PT1H\r\nSUMMARY:Windows TZ Event\r\n"
1711+
)
1712+
result = ical_to_jscal(ical)
1713+
assert result["timeZone"] == "America/New_York"
1714+
1715+
def test_globally_unique_tzid_is_normalized_to_iana(self):
1716+
"""Evolution/Mozilla Lightning-style vendor-prefixed TZIDs (RFC 5545
1717+
§3.2.19) must resolve to their IANA suffix."""
1718+
ical = _make_ical(
1719+
"DTSTART;TZID=/freeassociation.sourceforge.net/Europe/Berlin:20240615T100000\r\n"
1720+
"DURATION:PT1H\r\nSUMMARY:Globally Unique TZID Event\r\n"
1721+
)
1722+
result = ical_to_jscal(ical)
1723+
assert result["timeZone"] == "Europe/Berlin"
1724+
1725+
def test_custom_vtimezone_tzid_passes_through(self):
1726+
"""A TZID naming the event's own embedded VTIMEZONE (not a known
1727+
IANA/Windows name) isn't something tzid_from_dt can normalize
1728+
further, so it passes through unchanged."""
1729+
ical = (
1730+
"BEGIN:VCALENDAR\r\nVERSION:2.0\r\nPRODID:-//Test//Test//EN\r\n"
1731+
"BEGIN:VTIMEZONE\r\nTZID:Custom/MyOffice\r\n"
1732+
"BEGIN:STANDARD\r\nDTSTART:19701101T020000\r\n"
1733+
"TZOFFSETFROM:-0400\r\nTZOFFSETTO:-0500\r\nEND:STANDARD\r\n"
1734+
"END:VTIMEZONE\r\n"
1735+
"BEGIN:VEVENT\r\nUID:custom-tz@example.com\r\nDTSTAMP:20240101T000000Z\r\n"
1736+
"DTSTART;TZID=Custom/MyOffice:20240615T100000\r\n"
1737+
"DURATION:PT1H\r\nSUMMARY:Custom VTIMEZONE Event\r\n"
1738+
"END:VEVENT\r\nEND:VCALENDAR\r\n"
1739+
)
1740+
result = ical_to_jscal(ical)
1741+
assert result["timeZone"] == "Custom/MyOffice"
1742+
17041743
def test_prop_date_or_datetime_rejects_non_date_value(self):
17051744
from calendaring_jmap.convert.ical_to_jscal import _prop_date_or_datetime
17061745

0 commit comments

Comments
 (0)