From: Matthew Vernon Date: Tue, 11 Dec 2018 15:07:21 +0000 (+0000) Subject: Use start timezone for finding recurrences, and date only for all-days X-Git-Tag: v0.2~2 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~matthewv/git?a=commitdiff_plain;h=9b499a6a0e82d88812fd184aa52d3ba5647f83bd;p=gooswapper Use start timezone for finding recurrences, and date only for all-days This enables the correct recurrence to be found; in particular all-day events should be search for with only the start date, not the start timestamp. --- diff --git a/gooswapper.py b/gooswapper.py index 05db810..a9da368 100644 --- a/gooswapper.py +++ b/gooswapper.py @@ -97,13 +97,18 @@ def get_ex_event_by_id_and_changekey(acct,itemid,changekey): def get_gcal_event_by_eventid(gcal_acct,eventId,gcal_id="primary"): return gcal_acct.events().get(calendarId=gcal_id,eventId=eventId).execute() -def get_gcal_recur_instance(gcal_acct,gcal_master,start,gcal_id="primary"): +def get_gcal_recur_instance(gcal_acct,gcal_master,start,is_all_day,stz, + gcal_id="primary"): if gcal_master is None: logger.warning("Cannot get recurrences from event with null gcal id") return None + if is_all_day: + os = str(start.astimezone(stz).date()) + else: + os = start.astimezone(stz).isoformat() ans = gcal_acct.events().instances(calendarId=gcal_id, eventId=gcal_master, - originalStart=start.isoformat(), + originalStart=os, showDeleted=True).execute() if len(ans['items']) != 1: logger.error("Searching for recurrance instance returned %d events" % \ @@ -243,7 +248,10 @@ def modify_recurring(ex_acct,gcal_acct,gcal_tz, if master.modified_occurrences is not None: for mod in master.modified_occurrences: instance = get_gcal_recur_instance(gcal_acct,master.gcal_link, - mod.original_start,gcal_id) + mod.original_start, + master.is_all_day, + master._start_timezone, + gcal_id) if instance is None: #give up after first failure return mod_event = get_ex_event_by_itemid(ex_acct.calendar,mod.item_id) @@ -257,7 +265,10 @@ def modify_recurring(ex_acct,gcal_acct,gcal_tz, if master.deleted_occurrences is not None: for d in master.deleted_occurrences: instance = get_gcal_recur_instance(gcal_acct,master.gcal_link, - d.start,gcal_id) + d.start, + master.is_all_day, + master._start_timezone, + gcal_id) if instance is None: #give up after any failure return if instance["status"] != "cancelled":