From 04f537fd010b95c2cd543bee9de64bba8271c01b Mon Sep 17 00:00:00 2001 From: Christian Franke Date: Mon, 2 May 2016 14:36:12 +0200 Subject: Use timezone in calendar script --- scripts/get_calendar.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'scripts') diff --git a/scripts/get_calendar.py b/scripts/get_calendar.py index 89daf07..20a8b6f 100644 --- a/scripts/get_calendar.py +++ b/scripts/get_calendar.py @@ -11,6 +11,9 @@ import os 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. @@ -81,6 +84,10 @@ def get_events(calendar, after, before): if end.hour == 0 and end.minute == 0 and end.second == 0: end -= timedelta(seconds=1) + if start.tzinfo is None: + start = berlin.localize(start) + if end.tzinfo is None: + end = berlin.localize(end) if 'rrule' in event: rrule = rrulestr(event['rrule'].to_ical(), dtstart=start) duration = end - start @@ -131,15 +138,15 @@ if __name__ == '__main__': logging.basicConfig(stream=sys.stderr, level=logging.ERROR) logger = logging.getLogger('calendar_feed') regen, calendar = fetch_calendar(logger) - now = datetime.now() + now = berlin.localize(datetime.now()) after = now - relativedelta(days=1) before = now + relativedelta(months=+1) - after_tab = datetime(now.year,now.month,1); + after_tab = berlin.localize(datetime(now.year,now.month,1)) if now.month + 2 > 12: - before_tab = datetime(now.year+1,now.month + 10,1) + before_tab = berlin.localize(datetime(now.year+1,now.month + 10,1)) else: - before_tab = datetime(now.year,now.month+2,1) + before_tab = berlin.localize(datetime(now.year,now.month+2,1)) changed = put_events(calendar, after, before, os.path.join(base_path, '../template/calendar.json')) -- cgit v1.2.1