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/news/876.feature.1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Created the :attr:`vUTCOffset.ical_value <icalendar.prop.dt.utc_offset.vUTCOffset.ical_value>` property. @GabrielGervasio

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The correct location should be news/876.feature.1, not news/news/876.feature.1.

Suggested change
Created the :attr:`vUTCOffset.ical_value <icalendar.prop.dt.utc_offset.vUTCOffset.ical_value>` property. @GabrielGervasio
Added :attr:`~icalendar.prop.dt.utc_offset.vUTCOffset.ical_value`, which returns the UTC offset as a :class:`~datetime.timedelta`. AI was used as a reference for understanding the existing code and tests. :user:`GabrielGervasio`

5 changes: 5 additions & 0 deletions src/icalendar/prop/dt/utc_offset.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,11 @@ def __init__(self, td: timedelta, /, params: dict[str, Any] | None = None) -> No
self.td = td
self.params = Parameters(params)

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

def to_ical(self) -> str:
"""Return the ical representation."""
return self.format("")
Expand Down
4 changes: 4 additions & 0 deletions src/icalendar/tests/prop/test_unit.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,10 @@ def test_prop_vUTCOffset(self):

assert vUTCOffset(timedelta(hours=1, minutes=30)).to_ical() == "+0130"

# Test ical_value
assert vUTCOffset(timedelta(hours=2)).ical_value == timedelta(hours=2)
assert vUTCOffset(timedelta(hours=-5)).ical_value == timedelta(hours=-5)

# Support seconds
assert (
vUTCOffset(timedelta(hours=1, minutes=30, seconds=7)).to_ical() == "+013007"
Expand Down