# HG changeset patch # User Paul Boddie # Date 1508530880 -7200 # Node ID 4e16a443bb23f68685703b60fc0713a0fe08e84b # Parent f184dc45aadfa13a1951f1cb557192b93500ac8e Introduced a dedicated function for creating rule-originating period instances. Changed the fallback time zones used by RDATE and EXDATE period instances. diff -r f184dc45aadf -r 4e16a443bb23 imiptools/data.py --- a/imiptools/data.py Wed Oct 18 00:57:40 2017 +0200 +++ b/imiptools/data.py Fri Oct 20 22:21:20 2017 +0200 @@ -1089,6 +1089,24 @@ return delegators +def make_rule_period(start, duration, tzid, attr): + + """ + Make a period for the rule period starting at 'start' with the given + 'duration' employing the given 'tzid' and datetime 'attr'. + """ + + # Determine the resolution of the period. + + create = len(start) == 3 and date or datetime + start = to_timezone(create(*start), tzid) + end = start + duration + + # Create the period with accompanying metadata based on the main + # period and event details. + + return RecurringPeriod(start, end, tzid, "RRULE", attr) + def get_periods(obj, tzid, start=None, end=None, inclusive=False): """ @@ -1134,7 +1152,7 @@ until = parameters.get("UNTIL") if until: - until_dt = to_timezone(get_datetime(until, dtstart_attr), obj_tzid) + until_dt = to_timezone(get_datetime(until, dtstart_attr), obj_tzid or tzid) end = end and min(until_dt, end) or until_dt inclusive = True @@ -1148,17 +1166,7 @@ # done after the instances have been obtained. for recurrence_start in selector.materialise(dtstart, end, parameters.get("COUNT"), parameters.get("BYSETPOS"), inclusive): - - # Determine the resolution of the period. - - create = len(recurrence_start) == 3 and date or datetime - recurrence_start = to_timezone(create(*recurrence_start), obj_tzid) - recurrence_end = recurrence_start + main_period.get_duration() - - # Create the period with accompanying metadata based on the main - # period and event details. - - period = RecurringPeriod(recurrence_start, recurrence_end, tzid, "RRULE", dtstart_attr) + period = make_rule_period(recurrence_start, main_period.get_duration(), obj_tzid or tzid, dtstart_attr) # Filter out periods before the start. @@ -1170,7 +1178,7 @@ # Add recurrence dates. - rdates = obj.get_date_value_item_periods("RDATE", tzid) + rdates = obj.get_date_value_item_periods("RDATE", obj_tzid or tzid) if rdates: periods += rdates @@ -1180,7 +1188,7 @@ # Exclude exception dates. - exdates = obj.get_date_value_item_periods("EXDATE", tzid) + exdates = obj.get_date_value_item_periods("EXDATE", obj_tzid or tzid) if exdates: for period in exdates: