diff --git a/src/icalendar/prop/dt/time.py b/src/icalendar/prop/dt/time.py index a592bf00d..aebb90120 100644 --- a/src/icalendar/prop/dt/time.py +++ b/src/icalendar/prop/dt/time.py @@ -152,6 +152,26 @@ def is_utc(self) -> bool: """Whether this time is UTC.""" return self.params.is_utc() or is_utc(self.dt) + @property + def ical_value(self) -> time: + """Return the Python time value. + + This property provides access to the underlying Python :class:`datetime.time` + object that this iCalendar TIME value wraps. + + Returns: + time: The Python time object, potentially with timezone information. + + Example: + >>> from datetime import time + >>> vTime(time(12, 30, 0)).ical_value + datetime.time(12, 30, 0) + + See Also: + :rfc:`5545#section-3.3.12` for the TIME value type specification. + """ + return self.dt + @staticmethod def from_ical(ical: str, timezone: str | None | tzinfo = None) -> time: """Convert an ical string into a time. diff --git a/src/icalendar/tests/prop/test_vTime.py b/src/icalendar/tests/prop/test_vTime.py new file mode 100644 index 000000000..7bc40c509 --- /dev/null +++ b/src/icalendar/tests/prop/test_vTime.py @@ -0,0 +1,36 @@ +"""Test vTime ical_value property.""" + +from datetime import time, timezone + +from icalendar.prop import vTime + + +def test_ical_value_local_time(): + """ical_value property returns time object for local time.""" + t = time(12, 30, 45) + vt = vTime(t) + assert vt.ical_value == t + assert vt.ical_value.hour == 12 + assert vt.ical_value.minute == 30 + assert vt.ical_value.second == 45 + assert vt.ical_value.tzinfo is None + + +def test_ical_value_utc_time(): + """ical_value property returns time object with UTC timezone.""" + t = time(14, 0, 0, tzinfo=timezone.utc) + vt = vTime(t) + assert vt.ical_value == t + assert vt.ical_value.tzinfo == timezone.utc + + +def test_ical_value_from_ical(): + """ical_value property works with time parsed from ical string.""" + t = vTime.from_ical("123045") + vt = vTime(t) + assert vt.ical_value == time(12, 30, 45) + + t_utc = vTime.from_ical("140000Z") + vt_utc = vTime(t_utc) + assert vt_utc.ical_value.hour == 14 + assert vt_utc.ical_value.tzinfo is not None # Has timezone info