1.1 --- a/imiptools/data.py Fri Oct 20 01:06:09 2017 +0200
1.2 +++ b/imiptools/data.py Fri Oct 20 22:40:55 2017 +0200
1.3 @@ -1214,6 +1214,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, start=None, end=None, inclusive=False):
1.26
1.27 """
1.28 @@ -1240,11 +1258,6 @@
1.29 dtstart = main_period.get_start()
1.30 dtstart_attr = main_period.get_start_attr()
1.31
1.32 - # Attempt to get time zone details from the object, using the supplied zone
1.33 - # only as a fallback.
1.34 -
1.35 - obj_tzid = obj.get_tzid()
1.36 -
1.37 if not rrule:
1.38 periods = [main_period]
1.39
1.40 @@ -1260,7 +1273,7 @@
1.41
1.42 until = parameters.get("UNTIL")
1.43 if until:
1.44 - until_dt = to_timezone(get_datetime(until, dtstart_attr), obj_tzid)
1.45 + until_dt = to_timezone(get_datetime(until, dtstart_attr), tzid)
1.46 end = end and min(until_dt, end) or until_dt
1.47 inclusive = True
1.48
1.49 @@ -1276,16 +1289,7 @@
1.50 for recurrence_start in selector.materialise(dtstart, end,
1.51 parameters.get("COUNT"), parameters.get("BYSETPOS"), inclusive):
1.52
1.53 - # Determine the resolution of the period.
1.54 -
1.55 - create = len(recurrence_start) == 3 and date or datetime
1.56 - recurrence_start = to_timezone(create(*recurrence_start), obj_tzid)
1.57 - recurrence_end = recurrence_start + main_period.get_duration()
1.58 -
1.59 - # Create the period with accompanying metadata based on the main
1.60 - # period and event details.
1.61 -
1.62 - period = RecurringPeriod(recurrence_start, recurrence_end, tzid, "RRULE", dtstart_attr)
1.63 + period = make_rule_period(recurrence_start, main_period.get_duration(), tzid, dtstart_attr)
1.64
1.65 # Use the main period where it occurs.
1.66