# HG changeset patch # User Paul Boddie # Date 1508865208 -7200 # Node ID b3ba19f3e74dee1118e73f73618549365baf7522 # Parent c32240f8019d2cf160069dac38445f98bd7b5d26 Fixed and reorganised the rule period abstractions. diff -r c32240f8019d -r b3ba19f3e74d imiptools/data.py --- a/imiptools/data.py Tue Oct 24 18:57:49 2017 +0200 +++ b/imiptools/data.py Tue Oct 24 19:13:28 2017 +0200 @@ -1119,21 +1119,22 @@ """ self.rrule = rrule - self.start = main_period.get_start() - self.attr = main_period.get_start_attr() - self.duration = main_period.get_duration() + self.main_period = main_period + self.tzid = tzid parameters = rrule and get_parameters(rrule) until = parameters.get("UNTIL") + # Any UNTIL qualifier changes the nature of the end of the collection. + if until: + attr = main_period.get_start_attr() until_dt = to_timezone(get_datetime(until, attr), tzid) - end = end and min(until_dt, end) or until_dt - inclusive = True - - self.tzid = tzid - self.end = end - self.inclusive = inclusive + self.end = end and min(until_dt, end) or until_dt + self.inclusive = True + else: + self.end = end + self.inclusive = inclusive def __iter__(self): @@ -1143,19 +1144,19 @@ done after the instances have been obtained. """ - selector = get_rule(self.start, self.rrule) + start = self.main_period.get_start() + selector = get_rule(start, self.rrule) - return RulePeriodIterator(self.duration, self.attr, self.tzid, - selector.select(self.start, self.end, - self.inclusive)) + return RulePeriodIterator(self.main_period, self.tzid, + selector.select(start, self.end, self.inclusive)) class RulePeriodIterator: "An iterator over rule periods." - def __init__(self, duration, attr, tzid, iterator): - self.duration = duration - self.attr = attr + def __init__(self, main_period, tzid, iterator): + self.attr = main_period.get_start_attr() + self.duration = main_period.get_duration() self.tzid = tzid self.iterator = iterator