| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
"""Calculate repetitions of icalendar components.""" |
| 14 |
|
| 15 |
from __future__ import annotations |
| 16 |
|
| 17 |
from typing import TYPE_CHECKING |
| 18 |
|
| 19 |
import x_wr_timezone |
| 20 |
|
| 21 |
from recurring_ical_events.adapters import ( |
| 22 |
AbsoluteAlarmAdapter, |
| 23 |
ComponentAdapter, |
| 24 |
EventAdapter, |
| 25 |
JournalAdapter, |
| 26 |
TodoAdapter, |
| 27 |
) |
| 28 |
from recurring_ical_events.constants import DATE_MAX, DATE_MAX_DT, DATE_MIN, DATE_MIN_DT |
| 29 |
from recurring_ical_events.errors import ( |
| 30 |
BadRuleStringFormat, |
| 31 |
InvalidCalendar, |
| 32 |
PeriodEndBeforeStart, |
| 33 |
) |
| 34 |
from recurring_ical_events.examples import example_calendar |
| 35 |
from recurring_ical_events.query import T_COMPONENTS, CalendarQuery |
| 36 |
from recurring_ical_events.selection import ( |
| 37 |
Alarms, |
| 38 |
AllKnownComponents, |
| 39 |
ComponentsWithName, |
| 40 |
SelectComponents, |
| 41 |
) |
| 42 |
|
| 43 |
from .occurrence import AlarmOccurrence, Occurrence, OccurrenceID |
| 44 |
from .series import ( |
| 45 |
AbsoluteAlarmSeries, |
| 46 |
AlarmSeriesRelativeToEnd, |
| 47 |
AlarmSeriesRelativeToStart, |
| 48 |
Series, |
| 49 |
) |
| 50 |
|
| 51 |
if TYPE_CHECKING: |
| 52 |
from icalendar.cal import Component |
| 53 |
|
| 54 |
|
| 55 |
def of( |
| 56 |
a_calendar: Component, |
| 57 |
keep_recurrence_attributes=False, |
| 58 |
components: T_COMPONENTS = ("VEVENT",), |
| 59 |
skip_bad_series: bool = False, |
| 60 |
calendar_query: type[CalendarQuery] = CalendarQuery, |
| 61 |
) -> CalendarQuery: |
| 62 |
"""Create a query for recurring components in a_calendar. |
| 63 |
|
| 64 |
If the argument is a calendar, this will also correct |
| 65 |
times according to ``X-WR-TIMEZONE``. |
| 66 |
|
| 67 |
Arguments: |
| 68 |
a_calendar: an :class:`icalendar.cal.Calendar` component like |
| 69 |
:class:`icalendar.cal.Calendar`. |
| 70 |
keep_recurrence_attributes: Whether to keep attributes that are only used |
| 71 |
to calculate the recurrence (``RDATE``, ``EXDATE``, ``RRULE``). |
| 72 |
components: A list of component type names of which the recurrences |
| 73 |
should be returned. This can also be instances of :class:`SelectComponents`. |
| 74 |
Examples: ``("VEVENT", "VTODO", "VJOURNAL", "VALARM")`` |
| 75 |
skip_bad_series: Whether to skip series of components that contain |
| 76 |
errors. You can use :attr:`CalendarQuery.suppressed_errors` to |
| 77 |
specify which errors to skip. |
| 78 |
calendar_query: The :class:`CalendarQuery` class to use. |
| 79 |
""" |
| 80 |
a_calendar = x_wr_timezone.to_standard(a_calendar) |
| 81 |
return calendar_query( |
| 82 |
a_calendar, keep_recurrence_attributes, components, skip_bad_series |
| 83 |
) |
| 84 |
|
| 85 |
|
| 86 |
__all__ = [ |
| 87 |
"DATE_MAX", |
| 88 |
"DATE_MAX_DT", |
| 89 |
"DATE_MIN", |
| 90 |
"DATE_MIN_DT", |
| 91 |
"AbsoluteAlarmAdapter", |
| 92 |
"AbsoluteAlarmSeries", |
| 93 |
"AlarmOccurrence", |
| 94 |
"AlarmSeriesRelativeToEnd", |
| 95 |
"AlarmSeriesRelativeToStart", |
| 96 |
"Alarms", |
| 97 |
"AllKnownComponents", |
| 98 |
"BadRuleStringFormat", |
| 99 |
"CalendarQuery", |
| 100 |
"ComponentAdapter", |
| 101 |
"ComponentsWithName", |
| 102 |
"EventAdapter", |
| 103 |
"InvalidCalendar", |
| 104 |
"JournalAdapter", |
| 105 |
"Occurrence", |
| 106 |
"OccurrenceID", |
| 107 |
"PeriodEndBeforeStart", |
| 108 |
"SelectComponents", |
| 109 |
"Series", |
| 110 |
"TodoAdapter", |
| 111 |
"example_calendar", |
| 112 |
"of", |
| 113 |
] |