chiark / gitweb /
Handle the remaining recurrence types
authorMatthew Vernon <mv3@sanger.ac.uk>
Tue, 23 Oct 2018 15:12:47 +0000 (16:12 +0100)
committerMatthew Vernon <mv3@sanger.ac.uk>
Tue, 23 Oct 2018 15:12:47 +0000 (16:12 +0100)
These are in simple forms, as can be generated via the Outlook web
UI...

gooswapper.py

index d983303..dbc4204 100644 (file)
@@ -153,6 +153,15 @@ def ex_event_changes(old,new):
 def rr_daystr_from_int(i):
     return exchangelib.recurrence._weekday_to_str(i).upper()[:2]
 
+#for monthly patterns, we want the week (or -1 for last) combined with each
+#day specified
+def rr_daystr_monthly(p):
+    if p.week_number == 5:
+        wn = "-1"
+    else:
+        wn = str(p.week_number)
+    return ",".join([wn + rr_daystr_from_int(x) for x in p.weekdays])
+
 def rrule_from_ex(event,gcal_tz):
     if event.type != "RecurringMaster":
         logger.error("Cannot make recurrence from not-recurring event")
@@ -169,12 +178,35 @@ def rrule_from_ex(event,gcal_tz):
                           (event.recurrence.pattern.interval,
                            ",".join([rr_daystr_from_int(x) for x in event.recurrence.pattern.weekdays]),
                            rr_daystr_from_int(event.recurrence.pattern.first_day_of_week) )
+    elif isinstance(event.recurrence.pattern,
+                    exchangelib.recurrence.RelativeMonthlyPattern):
+        rr = "RRULE:FREQ=MONTHLY;INTERVAL=%d;BYDAY=%s" % \
+                     (event.recurrence.pattern.interval,
+                      rr_daystr_monthly(event.recurrence.pattern))
+    elif isinstance(event.recurrence.pattern,
+                    exchangelib.recurrence.AbsoluteMonthlyPattern):
+        rr = "RRULE:FREQ=MONTHLY;INTERVAL=%d;BYMONTHDAY=%d" % \
+                          (event.recurrence.pattern.interval,
+                           event.recurrence.pattern.day_of_month)
+    elif isinstance(event.recurrence.pattern,
+                    exchangelib.recurrence.AbsoluteYearlyPattern):
+        rr = "RRULE:FREQ=YEARLY;BYMONTH=%d;BYMONTHDAY=%d" % \
+                          (event.recurrence.pattern.month,
+                           event.recurrence.pattern.day_of_month)
+    elif isinstance(event.recurrence.pattern,
+                    exchangelib.recurrence.RelativeYearlyPattern):
+        rr = "RRULE:FREQ=YEARLY;BYMONTH=%d;BYDAY=%s" % \
+                          (event.recurrence.pattern.month,
+                           rr_daystr_monthly(event.recurrence.pattern))
     else:
         logger.error("Recurrence %s not supported" % event.recurrence)
         return None
     if isinstance(event.recurrence.boundary,
                   exchangelib.recurrence.EndDatePattern):
         rr += ";UNTIL={0:%Y}{0:%m}{0:%d}".format(event.recurrence.boundary.end)
+    elif isinstance(event.recurrence.boundary,
+                    exchangelib.recurrence.NoEndPattern):
+        pass #no end date to set
     else:
         logger.error("Recurrence %s not supported" % event.recurrence)
         return None