diff --git a/vobject/icalendar.py b/vobject/icalendar.py index bcc4fab..77e0c17 100644 --- a/vobject/icalendar.py +++ b/vobject/icalendar.py @@ -445,12 +445,19 @@ def getrruleset(self, addRDate=False): # a Ruby iCalendar library escapes semi-colons in rrules, # so also remove any backslashes value = line.value.replace('\\', '') - rule = rrule.rrulestr( - value, dtstart=dtstart, - # If dtstart has no time zone, `until` - # shouldn't get one, either: - ignoretz=isinstance(dtstart, datetime.date)) - until = rule._until + # If dtstart has no time zone, `until` + # shouldn't get one, either: + ignoretz = (not isinstance(dtstart, datetime.datetime) or + dtstart.tzinfo is None) + try: + until = rrule.rrulestr(value, ignoretz=ignoretz)._until + except ValueError: + # WORKAROUND: dateutil<=2.7.2 doesn't set the time zone + # of dtstart + if ignoretz: + raise + utc_now = datetime.datetime.now(datetime.timezone.utc) + until = rrule.rrulestr(value, dtstart=utc_now)._until if until is not None and isinstance(dtstart, datetime.datetime) and \ @@ -488,7 +495,12 @@ def getrruleset(self, addRDate=False): if dtstart.tzinfo is None: until = until.replace(tzinfo=None) - rule._until = until + value_without_until = ';'.join( + pair for pair in value.split(';') + if pair.split('=')[0].upper() != 'UNTIL') + rule = rrule.rrulestr(value_without_until, + dtstart=dtstart, ignoretz=ignoretz) + rule._until = until # add the rrule or exrule to the rruleset addfunc(rule)