Skip to content
Snippets Groups Projects
Verified Commit 888645de authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Support exdate, rdate, exrule for calendar feeds

parent b007bea0
No related branches found
No related tags found
1 merge request!1148Calendar events and iCal feeds
Pipeline #130117 failed
......@@ -1541,6 +1541,10 @@ class CalendarEvent(CalendarEventMixin, ExtensiblePolymorphicModel):
related_name="amended_by",
)
def provide_list_in_timezone(self, seq):
"""Provide a list of datetimes in the saved timezone."""
return [dt.astimezone(self.timezone) if isinstance(dt, datetime) else dt for dt in seq]
@classmethod
def value_title(cls, reference_object: "CalendarEvent") -> str:
"""Return the title of the calendar event."""
......@@ -1568,6 +1572,28 @@ class CalendarEvent(CalendarEventMixin, ExtensiblePolymorphicModel):
# iCal only supports one RRULE per event as per RFC 5545 (change to older RFC 2445)
return build_rrule_from_recurrences_rrule(reference_object.recurrences.rrules[0])
@classmethod
def value_rdate(cls, reference_object: "CalendarEvent") -> Optional[list[datetime]]:
"""Return the rdate of the calendar event."""
if not reference_object.recurrences:
return None
return reference_object.provide_list_in_timezone(reference_object.recurrences.rdates)
@classmethod
def value_exrule(cls, reference_object: "CalendarEvent") -> Optional[vRecur]:
"""Return the exrule of the calendar event."""
if not reference_object.recurrences or not reference_object.recurrences.exrules:
return None
return [build_rrule_from_recurrences_rrule(r) for r in reference_object.recurrences.exrules]
@classmethod
def value_exdate(cls, reference_object: "CalendarEvent") -> Optional[list[datetime]]:
"""Return the exdate of the calendar event."""
if not reference_object.recurrences:
return None
# return reference_object.recurrences.exdates
return reference_object.provide_list_in_timezone(reference_object.recurrences.exdates)
@classmethod
def value_unique_id(cls, reference_object: "CalendarEvent") -> str:
"""Return an unique identifier for an event."""
......@@ -1727,6 +1753,20 @@ class Holiday(CalendarEvent):
return per_weekday
@classmethod
def get_ex_dates(cls, datetime_start, datetime_end, recurrence):
"""Get the dates to exclude for holidays."""
recurrence.dtstart = recurrence.dtstart.astimezone(timezone.get_current_timezone())
holiday_dates = [
h["DTSTART"].dt for h in Holiday.get_single_events(datetime_start, datetime_end)
]
exdates = [
h.astimezone(timezone.utc)
for h in recurrence.occurrences()
if h.date() in holiday_dates
]
return exdates
def __str__(self) -> str:
return self.holiday_name
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment