1.1 --- a/imipweb/data.py Wed Sep 13 00:11:22 2017 +0200
1.2 +++ b/imipweb/data.py Wed Sep 13 00:29:48 2017 +0200
1.3 @@ -358,6 +358,34 @@
1.4 active_periods[p] += 1
1.5 return active_periods
1.6
1.7 +def get_removed_periods(periods, still_to_remove):
1.8 +
1.9 + """
1.10 + From the recurrence 'periods', given details of those 'still_to_remove',
1.11 + return the remaining active periods and the periods to unschedule or
1.12 + exclude, using a tuple of the form (active, unscheduled, excluded).
1.13 + """
1.14 +
1.15 + to_remove = set()
1.16 +
1.17 + # Get all periods that are not replaced.
1.18 +
1.19 + active_periods = get_active_periods(periods)
1.20 +
1.21 + for period in still_to_remove:
1.22 + active_periods[period] -= 1
1.23 + to_remove.add(period)
1.24 +
1.25 + # Determine whether some periods are both removed and added.
1.26 +
1.27 + remaining = []
1.28 + for period, n in active_periods.items():
1.29 + if n > 0:
1.30 + remaining.append(period)
1.31 +
1.32 + to_remove.difference_update(remaining)
1.33 + return remaining, to_remove
1.34 +
1.35
1.36
1.37 # Form field extraction and serialisation.