From 5c0f2924d928d15f292c8b2f6acfc44b2bd361e1 Mon Sep 17 00:00:00 2001 From: Raj Gahoi Date: Thu, 19 Nov 2026 21:47:22 +0530 Subject: [PATCH] fix: preserve TZID parameter and timezone in jCal vTime parsing (#2154) When parsing a jCal TIME property with a `tzid` parameter via `vTime.from_jcal`, the parameter dictionary was passed into `cls(value, params=...)` with an unlocalized naive `datetime.time`. `vTime.__init__` invoked `update_tzid_from(self.dt)`, which cleared the `tzid` from the parameters because `self.dt` lacked a timezone, causing the parsed property to lose its timezone and serialize to floating time. Localize `value` with `tzp.localize(value, params.tzid)` in `vTime.from_jcal` prior to instantiation, matching `vDatetime.from_jcal` and ensuring both `dt.tzinfo` and `params['TZID']` are preserved across jCal round trips. Resolves #2154 Signed-off-by: Raj Gahoi --- news/2154.bugfix | 1 + src/icalendar/prop/dt/time.py | 5 ++++- .../tests/rfc_7265_jcal/test_section_3_6_values.py | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 news/2154.bugfix diff --git a/news/2154.bugfix b/news/2154.bugfix new file mode 100644 index 000000000..7a7fbd6e8 --- /dev/null +++ b/news/2154.bugfix @@ -0,0 +1 @@ +Fixed :meth:`~icalendar.prop.dt.time.vTime.from_jcal` to preserve the TZID parameter and timezone on parsed TIME properties (:rfc:`7265`). @RajGahoi diff --git a/src/icalendar/prop/dt/time.py b/src/icalendar/prop/dt/time.py index bed3b10d1..48bbd1726 100644 --- a/src/icalendar/prop/dt/time.py +++ b/src/icalendar/prop/dt/time.py @@ -263,11 +263,14 @@ def from_jcal(cls, jcal_property: list) -> Self: ~icalendar.error.JCalParsingError: If the provided jCal is invalid. """ JCalParsingError.validate_property(jcal_property, cls) + params = Parameters.from_jcal_property(jcal_property) with JCalParsingError.reraise_with_path_added(3): value = cls.parse_jcal_value(jcal_property[3]) + if params.tzid: + value = tzp.localize(value, params.tzid) return cls( value, - params=Parameters.from_jcal_property(jcal_property), + params=params, ) def to_xcal(self, element: Element) -> None: diff --git a/src/icalendar/tests/rfc_7265_jcal/test_section_3_6_values.py b/src/icalendar/tests/rfc_7265_jcal/test_section_3_6_values.py index 8694ee5c2..1b94fe709 100644 --- a/src/icalendar/tests/rfc_7265_jcal/test_section_3_6_values.py +++ b/src/icalendar/tests/rfc_7265_jcal/test_section_3_6_values.py @@ -243,3 +243,17 @@ def test_jcal_round_trip_preserves_value_parameter(ics_line, prop_name, expected if isinstance(prop, list): prop = prop[0] assert prop.params.get("VALUE") == expected_value + + +def test_jcal_time_with_tzid_preserves_timezone(): + """A jCal TIME property with a TZID retains its timezone and survives round-trip (GH #2154).""" + jcal = [ + "vevent", + [["x-time", {"tzid": "Asia/Dhaka"}, "time", "08:30:00"]], + [], + ] + event = Event.from_jcal(jcal) + prop = event["X-TIME"] + assert prop.dt.tzinfo is not None + assert prop.params.get("TZID") == "Asia/Dhaka" + assert event.to_jcal() == jcal