From cc08ea5d14618abf5d8a519683df8409e11889aa Mon Sep 17 00:00:00 2001 From: William Mortenson Date: Thu, 12 Nov 2026 17:02:55 -0600 Subject: [PATCH] Add ical_value property to vTime Part of #876. AI: Claude Opus 5.5 Prompt (summary): help draft an ical_value property for vTime following vDate.ical_value. Output: The property, docstring, tests, and news entry in this commit. I reviewed the code, placed the files, fixed the test file location, and ran the full test suite locally. --- news/876.feature.1 | 1 + src/icalendar/prop/dt/time.py | 11 +++++++++++ src/icalendar/tests/prop/test_vTime.py | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+) create mode 100644 news/876.feature.1 create mode 100644 src/icalendar/tests/prop/test_vTime.py 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