1.1 --- a/imiptools/period.py Mon Feb 08 01:20:23 2016 +0100
1.2 +++ b/imiptools/period.py Mon Feb 08 16:33:31 2016 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Managing and presenting periods of time.
1.6
1.7 -Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2014, 2015, 2016 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -539,8 +539,11 @@
1.13
1.14 If 'recurrenceids' is specified, remove all periods associated with 'uid'
1.15 that do not have a recurrence identifier in the given list.
1.16 +
1.17 + Return the removed periods.
1.18 """
1.19
1.20 + removed = []
1.21 i = 0
1.22 while i < len(freebusy):
1.23 fb = freebusy[i]
1.24 @@ -548,10 +551,13 @@
1.25 recurrenceids is None or
1.26 recurrenceids is not None and fb.recurrenceid not in recurrenceids
1.27 ):
1.28 + removed.append(freebusy[i])
1.29 del freebusy[i]
1.30 else:
1.31 i += 1
1.32
1.33 + return removed
1.34 +
1.35 def remove_affected_period(freebusy, uid, start):
1.36
1.37 """
1.38 @@ -560,8 +566,12 @@
1.39 identifier, converted to a datetime). A recurrence identifier is used to
1.40 provide an alternative time period whilst also acting as a reference to the
1.41 originally-defined occurrence.
1.42 +
1.43 + Return any removed period in a list.
1.44 """
1.45
1.46 + removed = []
1.47 +
1.48 search = Period(start, start)
1.49 found = bisect_left(freebusy, search)
1.50
1.51 @@ -571,11 +581,12 @@
1.52 # Stop looking if the start no longer matches the recurrence identifier.
1.53
1.54 if fb.get_start_point() != search.get_start_point():
1.55 - return
1.56 + break
1.57
1.58 # If the period belongs to the parent object, remove it and return.
1.59
1.60 if not fb.recurrenceid and uid == fb.uid:
1.61 + removed.append(freebusy[found])
1.62 del freebusy[found]
1.63 break
1.64
1.65 @@ -583,6 +594,8 @@
1.66
1.67 found += 1
1.68
1.69 + return removed
1.70 +
1.71 def periods_from(freebusy, period):
1.72
1.73 "Return the entries in 'freebusy' at or after 'period'."