1.1 --- a/imiptools/data.py Wed Oct 18 00:57:40 2017 +0200
1.2 +++ b/imiptools/data.py Fri Oct 20 22:21:20 2017 +0200
1.3 @@ -1089,6 +1089,24 @@
1.4
1.5 return delegators
1.6
1.7 +def make_rule_period(start, duration, tzid, attr):
1.8 +
1.9 + """
1.10 + Make a period for the rule period starting at 'start' with the given
1.11 + 'duration' employing the given 'tzid' and datetime 'attr'.
1.12 + """
1.13 +
1.14 + # Determine the resolution of the period.
1.15 +
1.16 + create = len(start) == 3 and date or datetime
1.17 + start = to_timezone(create(*start), tzid)
1.18 + end = start + duration
1.19 +
1.20 + # Create the period with accompanying metadata based on the main
1.21 + # period and event details.
1.22 +
1.23 + return RecurringPeriod(start, end, tzid, "RRULE", attr)
1.24 +
1.25 def get_periods(obj, tzid, start=None, end=None, inclusive=False):
1.26
1.27 """
1.28 @@ -1134,7 +1152,7 @@
1.29
1.30 until = parameters.get("UNTIL")
1.31 if until:
1.32 - until_dt = to_timezone(get_datetime(until, dtstart_attr), obj_tzid)
1.33 + until_dt = to_timezone(get_datetime(until, dtstart_attr), obj_tzid or tzid)
1.34 end = end and min(until_dt, end) or until_dt
1.35 inclusive = True
1.36
1.37 @@ -1148,17 +1166,7 @@
1.38 # done after the instances have been obtained.
1.39
1.40 for recurrence_start in selector.materialise(dtstart, end, parameters.get("COUNT"), parameters.get("BYSETPOS"), inclusive):
1.41 -
1.42 - # Determine the resolution of the period.
1.43 -
1.44 - create = len(recurrence_start) == 3 and date or datetime
1.45 - recurrence_start = to_timezone(create(*recurrence_start), obj_tzid)
1.46 - recurrence_end = recurrence_start + main_period.get_duration()
1.47 -
1.48 - # Create the period with accompanying metadata based on the main
1.49 - # period and event details.
1.50 -
1.51 - period = RecurringPeriod(recurrence_start, recurrence_end, tzid, "RRULE", dtstart_attr)
1.52 + period = make_rule_period(recurrence_start, main_period.get_duration(), obj_tzid or tzid, dtstart_attr)
1.53
1.54 # Filter out periods before the start.
1.55
1.56 @@ -1170,7 +1178,7 @@
1.57
1.58 # Add recurrence dates.
1.59
1.60 - rdates = obj.get_date_value_item_periods("RDATE", tzid)
1.61 + rdates = obj.get_date_value_item_periods("RDATE", obj_tzid or tzid)
1.62 if rdates:
1.63 periods += rdates
1.64
1.65 @@ -1180,7 +1188,7 @@
1.66
1.67 # Exclude exception dates.
1.68
1.69 - exdates = obj.get_date_value_item_periods("EXDATE", tzid)
1.70 + exdates = obj.get_date_value_item_periods("EXDATE", obj_tzid or tzid)
1.71
1.72 if exdates:
1.73 for period in exdates: