Skip to content

Commit 206360c

Browse files
fix(jmap): replace deprecated pytz with stdlib zoneinfo in jscal_to_ical
Apply suggestions from code review
1 parent 703ad6b commit 206360c

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

caldav/jmap/convert/jscal_to_ical.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from __future__ import annotations
1212

1313
from datetime import date, datetime, timedelta, timezone
14+
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
1415

1516
import icalendar
1617
from icalendar import vCalAddress, vText
@@ -75,6 +76,16 @@ def _start_to_dtstart(
7576
def _add_dtstart_tzid_passthrough():
7677
dtstart = icalendar.vDatetime(dt_naive)
7778
dtstart.params["TZID"] = time_zone
79+
if time_zone:
80+
try:
81+
tz = ZoneInfo(time_zone)
82+
dt = dt_naive.replace(tzinfo=tz)
83+
component.add("dtstart", dt)
84+
except ZoneInfoNotFoundError:
85+
# Non-IANA TZID (e.g. "Eastern Standard Time") — pass through as-is
86+
# so the consuming calendar client can resolve it.
87+
dtstart = icalendar.vDatetime(dt_naive)
88+
dtstart.params["TZID"] = time_zone
7889
component.add("dtstart", dtstart)
7990

8091
try:

0 commit comments

Comments
 (0)