Skip to content

Commit

Permalink
Fix recurrence rule UNTIL string serialization (#122)
Browse files Browse the repository at this point in the history
* Update recurrence rule marshalling

* Use type instead of key for value serialization
  • Loading branch information
allenporter authored Oct 9, 2022
1 parent 085610f commit e203059
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ical/types/recur.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ def __encode_property_value__(cls, data: dict[str, Any]) -> str:
occurrence = ""
values.append(f"{occurrence}{weekday}")
value = ",".join(values)
elif isinstance(value, datetime.datetime):
value = DateTimeEncoder.__encode_property_json__(value)
if not value:
continue
result.append(f"{key.upper()}={value}")
Expand Down
15 changes: 15 additions & 0 deletions tests/types/test_recur.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,18 @@ def test_recur_as_string() -> None:
)
assert event.rrule
assert event.rrule.as_rrule_str() == "FREQ=DAILY;INTERVAL=2"


def test_recur_until_as_string() -> None:
"""Test converting a recurrence rule with a date into a string."""

event = Event(
summary="summary",
start=datetime.datetime(2022, 8, 1, 6, 0, 0),
end=datetime.datetime(2022, 8, 2, 6, 30, 0),
rrule=Recur(
freq=Frequency.DAILY, until=datetime.datetime(2022, 8, 10, 6, 0, 0)
),
)
assert event.rrule
assert event.rrule.as_rrule_str() == "FREQ=DAILY;UNTIL=20220810T060000;INTERVAL=1"

0 comments on commit e203059

Please sign in to comment.