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

fix some getrruleset() bugs #85

Merged
merged 2 commits into from
Jun 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 29 additions & 17 deletions vobject/icalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ def getrruleset(self, addRDate=False):
Get an rruleset created from self.

If addRDate is True, add an RDATE for dtstart if it's not included in
an RRULE, and count is decremented if it exists.
an RRULE or RDATE, and count is decremented if it exists.

Note that for rules which don't match DTSTART, DTSTART may not appear
in list(rruleset), although it should. By default, an RDATE is not
Expand All @@ -415,9 +415,11 @@ def getrruleset(self, addRDate=False):
if addfunc is None:
addfunc = getattr(rruleset, name)

dtstart = self.dtstart.value

if name in DATENAMES:
if type(line.value[0]) == datetime.datetime:
map(addfunc, line.value)
list(map(addfunc, line.value))
elif type(line.value[0]) == datetime.date:
for dt in line.value:
addfunc(datetime.datetime(dt.year, dt.month, dt.day))
Expand Down Expand Up @@ -492,26 +494,36 @@ def getrruleset(self, addRDate=False):
# add the rrule or exrule to the rruleset
addfunc(rule)

if name == 'rrule' and addRDate:
try:
# dateutils does not work with all-day
# (datetime.date) items so we need to convert to a
# datetime.datetime (which is what dateutils
# does internally)
if not isinstance(dtstart, datetime.datetime):
adddtstart = datetime.datetime.fromordinal(dtstart.toordinal())
else:
adddtstart = dtstart
if (name == 'rrule' or name == 'rdate') and addRDate:
# rlist = rruleset._rrule if name == 'rrule' else rruleset._rdate
try:
# dateutils does not work with all-day
# (datetime.date) items so we need to convert to a
# datetime.datetime (which is what dateutils
# does internally)
if not isinstance(dtstart, datetime.datetime):
adddtstart = datetime.datetime.fromordinal(dtstart.toordinal())
else:
adddtstart = dtstart

if name == 'rrule':
if rruleset._rrule[-1][0] != adddtstart:
rruleset.rdate(adddtstart)
added = True
if rruleset._rrule[-1]._count is not None:
rruleset._rrule[-1]._count -= 1
else:
added = False
except IndexError:
# it's conceivable that an rrule has 0 datetimes
added = False
if added and rruleset._rrule[-1]._count is not None:
rruleset._rrule[-1]._count -= 1
elif name == 'rdate':
if rruleset._rdate[0] != adddtstart:
rruleset.rdate(adddtstart)
added = True
else:
added = False
except IndexError:
# it's conceivable that an rrule has 0 datetimes
added = False

return rruleset

def setrruleset(self, rruleset):
Expand Down