diff --git a/news/876.feature.1 b/news/876.feature.1 new file mode 100644 index 000000000..ea9844785 --- /dev/null +++ b/news/876.feature.1 @@ -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 help verify the property, its tests, and to explain the contribution process for my first open source contribution, this was done after writing the code myself. @wmortenson199 \ No newline at end of file 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