chiark / gitweb /
Use start timezone for finding recurrences, and date only for all-days
authorMatthew Vernon <mv3@sanger.ac.uk>
Tue, 11 Dec 2018 15:07:21 +0000 (15:07 +0000)
committerMatthew Vernon <mv3@sanger.ac.uk>
Tue, 11 Dec 2018 15:07:21 +0000 (15:07 +0000)
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.

gooswapper.py

index 05db810ff0b5f226d91a6357e734815d1ccfbc76..a9da3680a7b86c095193aa641ef4bb87129d3ecc 100644 (file)
@@ -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_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 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,
     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" % \
                                        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,
     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)
             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,
     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":
             if instance is None: #give up after any failure
                 return
             if instance["status"] != "cancelled":