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