diff --git a/news/876.feature.3 b/news/876.feature.3 new file mode 100644 index 000000000..65b34329c --- /dev/null +++ b/news/876.feature.3 @@ -0,0 +1 @@ +Added the :attr:`vTime.ical_value ` property to :class:`vTime `, which returns the :class:`datetime.time` it represents. I used Claude Opus 5.5 to draft this property, its tests, and this entry for issue #876, then reviewed, placed, and tested the code myself. @wmortenson199 diff --git a/src/icalendar/prop/dt/time.py b/src/icalendar/prop/dt/time.py index bed3b10d1..d55edc6f8 100644 --- a/src/icalendar/prop/dt/time.py +++ b/src/icalendar/prop/dt/time.py @@ -161,6 +161,17 @@ 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 time of day as a :class:`datetime.time`. + + .. seealso:: + + :rfc:`5545#section-3.3.12` for the ``TIME`` value type. + + """ + 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..8821fc71c --- /dev/null +++ b/src/icalendar/tests/prop/test_vTime.py @@ -0,0 +1,19 @@ +"""Test vTime property.""" + +from datetime import time, timezone + +from icalendar.prop import vTime + + +def test_ical_value(): + """ical_value returns the time value.""" + value = time(8, 30, 0) + ical_time = vTime(value).ical_value + assert ical_time == value + assert type(ical_time) is time + + +def test_ical_value_utc(): + """ical_value keeps the UTC timezone.""" + value = time(13, 30, 0, tzinfo=timezone.utc) + assert vTime(value).ical_value == value