From 64164b837573bed3861786706c4395f6a08aaa04 Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Mon, 2 May 2016 14:54:12 +0200 Subject: Strip tzinfo from rrule until fields --- scripts/get_calendar.py | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/scripts/get_calendar.py b/scripts/get_calendar.py index 89daf07..9e48852 100644 --- a/scripts/get_calendar.py +++ b/scripts/get_calendar.py @@ -12,6 +12,10 @@ from dateutil.rrule import rrulestr import icalendar import subprocess +import pytz + +berlin = pytz.timezone('Europe/Berlin') + def fetch_calendar(logger): """Fetches the calendar events and returns a icalendar.Calendar instance. """ @@ -83,12 +87,18 @@ def get_events(calendar, after, before): if 'rrule' in event: rrule = rrulestr(event['rrule'].to_ical(), dtstart=start) + if rrule._until is not None and rrule._until.tzinfo is not None: + rrule._until = rrule._until.astimezone(berlin).replace(tzinfo=None) duration = end - start - for occurence in rrule.between(after, before, True): - event_info['start'] = occurence - event_info['end'] = occurence + duration - event_info['recurring'] = True - yield copy.deepcopy(event_info) + try: + for occurence in rrule.between(after, before, True): + event_info['start'] = occurence + event_info['end'] = occurence + duration + event_info['recurring'] = True + yield copy.deepcopy(event_info) + except TypeError: + import pdb + pdb.set_trace() else: if start >= after: event_info['start'] = start -- cgit v1.2.1