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.5
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added :attr:`~icalendar.prop.dt.types.vDDDTypes.ical_value` to return the underlying Python date, datetime, time, duration, or period value. I worked with OpenAI Codex to draft the property, docstring, and tests, then edited the files and ran the checks and full test suite locally. :user:`Jordanali418`
12 changes: 12 additions & 0 deletions src/icalendar/prop/dt/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,18 @@ def __init__(self, dt: DT_TYPE, params: dict[str, Any] | None = None) -> None:
self.params = Parameters(params)
self.params.update_tzid_from(dt)

@property
def ical_value(self) -> DT_TYPE:
"""Return the underlying Python date, time, duration, or period value.

Examples:
>>> from datetime import date
>>> from icalendar.prop import vDDDTypes
>>> vDDDTypes(date(2026, 11, 23)).ical_value
datetime.date(2026, 11, 23)
"""
return self.dt

def to_property_type(self) -> vDatetime | vDate | vDuration | vTime | vPeriod:
"""Convert to a property type.

Expand Down
25 changes: 25 additions & 0 deletions src/icalendar/tests/prop/test_vDDDTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,28 @@ def test_parse_jcal_value_uses_the_matching_parser(
for parser in unused_parsers:
monkeypatch.setattr(parser, "parse_jcal_value", fail)
assert vDDDTypes.parse_jcal_value(value) == expected


@pytest.mark.parametrize(
"value",
[
date(2026, 11, 23),
datetime(2026, 11, 23, 12, 30),
time(12, 30),
timedelta(hours=2),
(datetime(2026, 11, 23), datetime(2026, 11, 24)),
(datetime(2026, 11, 23), timedelta(hours=2)),
],
)
def test_ical_value(value):
"""Return the underlying Python value for every supported type."""
assert vDDDTypes(value).ical_value == value


def test_ical_value_preserves_timezone(tzp):
"""Keep the timezone of the underlying datetime."""
value = tzp.localize_utc(datetime(2026, 11, 23, 12, 30))
result = vDDDTypes(value).ical_value

assert result == value
assert result.tzinfo is value.tzinfo