From: Matthew Vernon Date: Tue, 11 Dec 2018 15:06:31 +0000 (+0000) Subject: Use event timezone for events (where available) X-Git-Tag: v0.2~3 X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~matthewv/git?p=gooswapper;a=commitdiff_plain;h=dd0a59a1e17ad158f5be15db8245fa76479afe87 Use event timezone for events (where available) This required a fix in the upstream exchange library (to properly understand the MS timezones), but now we can use the event's timezone. --- diff --git a/gooswapper.py b/gooswapper.py index 24b7a2f..05db810 100644 --- a/gooswapper.py +++ b/gooswapper.py @@ -270,14 +270,24 @@ def modify_recurring(ex_acct,gcal_acct,gcal_tz, def build_gcal_event_from_ex(event,gcal_tz): gevent={} gevent["summary"]=event.subject + #Use the event's timezones if possible, otherwise fall back to the + #target calendar timezone + if event._start_timezone is not None: + stz = event._start_timezone + else: + stz = gcal_tz + if event._end_timezone is not None: + etz = event._end_timezone + else: + etz = gcal_tz if event.is_all_day: - gevent["end"]={"date": str(event.end.astimezone(gcal_tz).date())} - gevent["start"]={"date": str(event.start.astimezone(gcal_tz).date())} + gevent["end"]={"date": str(event.end.astimezone(etz).date())} + gevent["start"]={"date": str(event.start.astimezone(stz).date())} else: - gevent["end"]={"dateTime": event.end.astimezone(gcal_tz).isoformat(), - "timeZone": str(gcal_tz)} - gevent["start"]={"dateTime": event.start.astimezone(gcal_tz).isoformat(), - "timeZone": str(gcal_tz)} + gevent["end"]={"dateTime": event.end.astimezone(etz).isoformat(), + "timeZone": str(etz)} + gevent["start"]={"dateTime": event.start.astimezone(stz).isoformat(), + "timeZone": str(stz)} if event.text_body is not None and event.text_body.strip() != '': gevent["description"] = event.text_body if event.location is not None: