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
2 changes: 1 addition & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Breaking changes
New features
~~~~~~~~~~~~

- ...
- Created a :meth:`~icalendar.prop.recur.weekday.vWeekday.ical_value` property for the :class:`~icalendar.prop.recur.weekday.vWeekday` component, mirroring the existing pattern on :class:`~icalendar.prop.boolean.vBoolean`. :pr:`1360`

Bug fixes
~~~~~~~~~
Expand Down
10 changes: 10 additions & 0 deletions src/icalendar/prop/recur/weekday.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ def from_ical(cls, ical):
except Exception as e:
raise ValueError(f"Expected weekday abbreviation, got: {ical}") from e

@property
def ical_value(self) -> str:
"""Returns the weekday value as a string, for example, ``MO``, ``+2TH``, or ``-1SU``.

See Also:

:rfc:`5545#section-3.3.10` for the ``BYDAY`` rule grammar.
"""
return str(self)

@classmethod
def parse_jcal_value(cls, value: Any) -> Self:
"""Parse a jCal value for vWeekday.
Expand Down
8 changes: 8 additions & 0 deletions src/icalendar/tests/prop/test_vWeekday.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,11 @@ def test_error():
"""Error: Expected weekday abbrevation, got: -100MO"""
with pytest.raises(ValueError):
vWeekday.from_ical("-100MO")


def test_ical_value():
"""ical_value property returns the weekday string value."""
assert vWeekday("MO").ical_value == "MO"
assert vWeekday("+2TH").ical_value == "+2TH"
assert vWeekday("-1SU").ical_value == "-1SU"
assert isinstance(vWeekday("MO").ical_value, str)