Skip to content
Closed
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
20 changes: 20 additions & 0 deletions src/icalendar/prop/dt/time.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
36 changes: 36 additions & 0 deletions src/icalendar/tests/prop/test_vTime.py
Original file line number Diff line number Diff line change
@@ -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
Loading