Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RRULE: Fix floating UNTIL with dateutil > 2.6.1 #115

Merged
merged 4 commits into from
Jul 8, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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