Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/876.feature.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added the :attr:`vTime.ical_value <icalendar.prop.dt.time.vTime.ical_value>` property to :class:`vTime <icalendar.prop.dt.time.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
11 changes: 11 additions & 0 deletions src/icalendar/prop/dt/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
19 changes: 19 additions & 0 deletions src/icalendar/tests/prop/test_vTime.py
Original file line number Diff line number Diff line change
@@ -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
Loading