Skip to content
Merged
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.2
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Created the :attr:`vDuration.ical_value <icalendar.prop.dt.duration.vDuration.ical_value>` property. I used AI to help with this change. @arrudagba
5 changes: 5 additions & 0 deletions src/icalendar/prop/dt/duration.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,11 @@ def dt(self) -> timedelta:
"""The time delta for compatibility."""
return self.td

@property
def ical_value(self) -> timedelta:
"""Duration as a :class:`~datetime.timedelta` according to :rfc:`5545#section-3.3.6`."""
return self.td

@classmethod
def examples(cls) -> list[Self]:
"""Examples of vDuration."""
Expand Down
35 changes: 35 additions & 0 deletions src/icalendar/tests/prop/test_vDuration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
"""Test the ical_value property of vDuration."""

from datetime import timedelta

import pytest

from icalendar import Event
from icalendar.prop import vDuration


@pytest.mark.parametrize(
"td",
[
timedelta(days=15, seconds=18020),
timedelta(weeks=7),
timedelta(hours=-5),
timedelta(days=-1, hours=-5),
timedelta(0),
],
)
def test_ical_value(td):
"""ical_value returns the timedelta of the duration."""
assert vDuration(td).ical_value == td


def test_ical_value_from_string():
"""ical_value also works when the duration is created from a string."""
assert vDuration("-P14D").ical_value == timedelta(days=-14)


def test_decoded_uses_ical_value():
"""Component.decoded() returns the ical_value of a DURATION."""
event = Event()
event.add("DURATION", timedelta(hours=2))
assert event.decoded("DURATION") == timedelta(hours=2)
Loading