diff --git a/ical/types/recur.py b/ical/types/recur.py index 6a03cf8..7ab391c 100644 --- a/ical/types/recur.py +++ b/ical/types/recur.py @@ -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}") diff --git a/tests/types/test_recur.py b/tests/types/test_recur.py index 69d0bda..089aa79 100644 --- a/tests/types/test_recur.py +++ b/tests/types/test_recur.py @@ -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"