1.1 --- a/imiptools/data.py Sun Mar 01 00:20:17 2015 +0100
1.2 +++ b/imiptools/data.py Sun Mar 01 00:24:11 2015 +0100
1.3 @@ -92,11 +92,15 @@
1.4
1.5 # Computed results.
1.6
1.7 - def get_periods(self, tzid, window_size=100):
1.8 - return get_periods(self, tzid, window_size)
1.9 + def has_recurrence(self, tzid, recurrence):
1.10 + recurrences = [start for start, end in get_periods(self, tzid, recurrence, True)]
1.11 + return recurrence in recurrences
1.12
1.13 - def get_periods_for_freebusy(self, tzid, window_size=100):
1.14 - periods = self.get_periods(tzid, window_size)
1.15 + def get_periods(self, tzid, end):
1.16 + return get_periods(self, tzid, end)
1.17 +
1.18 + def get_periods_for_freebusy(self, tzid, end):
1.19 + periods = self.get_periods(tzid, end)
1.20 return get_periods_for_freebusy(self, periods, tzid)
1.21
1.22 # Construction and serialisation.
1.23 @@ -339,11 +343,15 @@
1.24 # NOTE: Need to expose the 100 day window for recurring events in the
1.25 # NOTE: configuration.
1.26
1.27 -def get_periods(obj, tzid, window_size=100):
1.28 +def get_window_end(tzid, window_size=100):
1.29 + return to_timezone(datetime.now(), tzid) + timedelta(window_size)
1.30 +
1.31 +def get_periods(obj, tzid, window_end, inclusive=False):
1.32
1.33 """
1.34 Return periods for the given object 'obj', confining materialised periods
1.35 - to the given 'window_size' in days starting from the present moment.
1.36 + to before the given 'window_end' datetime. If 'inclusive' is set to a true
1.37 + value, any period occurring at the 'window_end' will be included.
1.38 """
1.39
1.40 rrule = obj.get_value("RRULE")
1.41 @@ -366,13 +374,11 @@
1.42 # for the agent, with instances outside that period being considered
1.43 # unchecked.
1.44
1.45 - window_end = to_timezone(datetime.now(), tzid) + timedelta(window_size)
1.46 -
1.47 selector = get_rule(dtstart, rrule)
1.48 parameters = get_parameters(rrule)
1.49 periods = []
1.50
1.51 - for start in selector.materialise(dtstart, window_end, parameters.get("COUNT"), parameters.get("BYSETPOS")):
1.52 + for start in selector.materialise(dtstart, window_end, parameters.get("COUNT"), parameters.get("BYSETPOS"), inclusive):
1.53 start = to_timezone(datetime(*start), tzid)
1.54 end = start + duration
1.55 periods.append((start, end))