Skip to content

Commit

Permalink
Merge pull request #115 from Unrud/patch-2
Browse files Browse the repository at this point in the history
RRULE: Fix floating UNTIL with dateutil > 2.6.1
  • Loading branch information
wpercy committed Jul 8, 2018
2 parents c4ae08b + 0ec6ad3 commit da73536
Showing 1 changed file with 19 additions and 7 deletions.
26 changes: 19 additions & 7 deletions vobject/icalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit da73536

Please sign in to comment.