Improved error handling

This commit is contained in:
Maximilian Giller 2019-07-05 21:30:14 +02:00
parent 464f489ebd
commit fdb4331aec

View file

@ -102,15 +102,19 @@ class CalendarInterface (DataSourceInterface):
end = start + duration end = start + duration
occurrences = [] occurrences = []
r_string=self.__add_timezoneawarness__(event.rrule) try:
rule=rrulestr(r_string,dtstart=event.begin_datetime) r_string=self.__add_timezoneawarness__(event.rrule)
for occurrence in rule: rule=rrulestr(r_string,dtstart=event.begin_datetime)
if occurrence - end > timedelta(0): for occurrence in rule:
return occurrences if occurrence - end > timedelta(0):
merged_event = self.__merge_event_data__(event, start=occurrence) return occurrences
if self.__is_onetime_in_range__(merged_event, start, duration): merged_event = self.__merge_event_data__(event, start=occurrence)
occurrences.append(merged_event) if self.__is_onetime_in_range__(merged_event, start, duration):
return occurrences occurrences.append(merged_event)
return occurrences
except Exception as ex:
print("\"is_repeating_in_range\" failed while processing: dtstart.tzinfo="+str(event.begin_datetime.tzinfo))
raise ex
def __merge_event_data__ (self, event, start = None): def __merge_event_data__ (self, event, start = None):
if start is not None: if start is not None:
@ -120,15 +124,16 @@ class CalendarInterface (DataSourceInterface):
return event return event
def __add_timezoneawarness__ (self, rrule): def __add_timezoneawarness__ (self, rrule):
"""UNTIL must be specified in UTC when DTSTART is timezone-aware (which it is)"""
if "UNTIL" not in rrule: if "UNTIL" not in rrule:
return rrule return rrule
timezone_str = "T000000Z" timezone_str = "T000000Z"
until_example = "UNTIL=YYYYMMDD" until_template = "UNTIL=YYYYMMDD"
until_index = rrule.index("UNTIL") until_index = rrule.index("UNTIL")
tz_index = until_index + len(until_example) tz_index = until_index + len(until_template)
if tz_index < 0 or tz_index >= len(rrule): if tz_index < 0 or tz_index >= len(rrule):
return rrule return rrule