1.1 --- a/imiptools/client.py Mon Feb 08 01:20:23 2016 +0100
1.2 +++ b/imiptools/client.py Mon Feb 08 16:33:31 2016 +0100
1.3 @@ -993,8 +993,11 @@
1.4
1.5 "Remove this event from the given 'freebusy' collection."
1.6
1.7 - if not remove_event_periods(freebusy, self.uid, self.recurrenceid) and self.recurrenceid:
1.8 - remove_affected_period(freebusy, self.uid, self.get_recurrence_start_point(self.recurrenceid))
1.9 + removed = remove_event_periods(freebusy, self.uid, self.recurrenceid)
1.10 + if not removed and self.recurrenceid:
1.11 + return remove_affected_period(freebusy, self.uid, self.get_recurrence_start_point(self.recurrenceid))
1.12 + else:
1.13 + return removed
1.14
1.15 def remove_freebusy_for_recurrences(self, freebusy, recurrenceids=None):
1.16
2.1 --- a/imiptools/period.py Mon Feb 08 01:20:23 2016 +0100
2.2 +++ b/imiptools/period.py Mon Feb 08 16:33:31 2016 +0100
2.3 @@ -3,7 +3,7 @@
2.4 """
2.5 Managing and presenting periods of time.
2.6
2.7 -Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk>
2.8 +Copyright (C) 2014, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
2.9
2.10 This program is free software; you can redistribute it and/or modify it under
2.11 the terms of the GNU General Public License as published by the Free Software
2.12 @@ -539,8 +539,11 @@
2.13
2.14 If 'recurrenceids' is specified, remove all periods associated with 'uid'
2.15 that do not have a recurrence identifier in the given list.
2.16 +
2.17 + Return the removed periods.
2.18 """
2.19
2.20 + removed = []
2.21 i = 0
2.22 while i < len(freebusy):
2.23 fb = freebusy[i]
2.24 @@ -548,10 +551,13 @@
2.25 recurrenceids is None or
2.26 recurrenceids is not None and fb.recurrenceid not in recurrenceids
2.27 ):
2.28 + removed.append(freebusy[i])
2.29 del freebusy[i]
2.30 else:
2.31 i += 1
2.32
2.33 + return removed
2.34 +
2.35 def remove_affected_period(freebusy, uid, start):
2.36
2.37 """
2.38 @@ -560,8 +566,12 @@
2.39 identifier, converted to a datetime). A recurrence identifier is used to
2.40 provide an alternative time period whilst also acting as a reference to the
2.41 originally-defined occurrence.
2.42 +
2.43 + Return any removed period in a list.
2.44 """
2.45
2.46 + removed = []
2.47 +
2.48 search = Period(start, start)
2.49 found = bisect_left(freebusy, search)
2.50
2.51 @@ -571,11 +581,12 @@
2.52 # Stop looking if the start no longer matches the recurrence identifier.
2.53
2.54 if fb.get_start_point() != search.get_start_point():
2.55 - return
2.56 + break
2.57
2.58 # If the period belongs to the parent object, remove it and return.
2.59
2.60 if not fb.recurrenceid and uid == fb.uid:
2.61 + removed.append(freebusy[found])
2.62 del freebusy[found]
2.63 break
2.64
2.65 @@ -583,6 +594,8 @@
2.66
2.67 found += 1
2.68
2.69 + return removed
2.70 +
2.71 def periods_from(freebusy, period):
2.72
2.73 "Return the entries in 'freebusy' at or after 'period'."