From f24cdc50d17847925d7dd24a74b98a07e6d255d0 Mon Sep 17 00:00:00 2001 From: jordanali418 Date: Mon, 23 Nov 2026 14:10:07 -0600 Subject: [PATCH] Add ical_value property to vDDDTypes Part of #876. AI assistance: OpenAI Codex (GPT-6) helped draft the property, docstring, and tests, explain the implementation, and troubleshoot validation. I edited the files and ran the checks and full test suite locally. --- news/876.feature.5 | 1 + src/icalendar/prop/dt/types.py | 12 +++++++++++ src/icalendar/tests/prop/test_vDDDTypes.py | 25 ++++++++++++++++++++++ 3 files changed, 38 insertions(+) create mode 100644 news/876.feature.5 diff --git a/news/876.feature.5 b/news/876.feature.5 new file mode 100644 index 000000000..ada1e548e --- /dev/null +++ b/news/876.feature.5 @@ -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` \ No newline at end of file diff --git a/src/icalendar/prop/dt/types.py b/src/icalendar/prop/dt/types.py index 06fd4538e..f69649e2b 100644 --- a/src/icalendar/prop/dt/types.py +++ b/src/icalendar/prop/dt/types.py @@ -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. diff --git a/src/icalendar/tests/prop/test_vDDDTypes.py b/src/icalendar/tests/prop/test_vDDDTypes.py index 823a5ef57..0a2f3b9fa 100644 --- a/src/icalendar/tests/prop/test_vDDDTypes.py +++ b/src/icalendar/tests/prop/test_vDDDTypes.py @@ -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