Skip to content

Commit

Permalink
Merge pull request #76 from htgoebel/issue-75
Browse files Browse the repository at this point in the history
Proposed fix for issue 75: handle offset-naive and offset-aware datetimes
  • Loading branch information
wpercy authored Jun 21, 2017
2 parents 63862f2 + 7b2db0e commit b2fbdb2
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 1 deletion.
9 changes: 9 additions & 0 deletions test_files/recurrence-offset-naive.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
DTSTART;VALUE=DATE:20130117
DTEND;VALUE=DATE:20130118
RRULE:FREQ=WEEKLY;UNTIL=20130330T230000Z;BYDAY=TH
SUMMARY:Meeting
END:VEVENT
END:VCALENDAR
9 changes: 9 additions & 0 deletions test_files/recurrence-without-tz.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
DTSTART;VALUE=DATE:20130117
DTEND;VALUE=DATE:20130118
RRULE:FREQ=WEEKLY;UNTIL=20130330;BYDAY=TH
SUMMARY:Meeting
END:VEVENT
END:VCALENDAR
23 changes: 23 additions & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,29 @@ def test_recurring_component(self):
[datetime.datetime(2005, 3, 18, 0, 0), datetime.datetime(2005, 3, 29, 0, 0)]
)

def test_recurrence_without_tz(self):
"""
Test recurring vevent missing any time zone definitions.
"""
test_file = get_test_file("recurrence-without-tz.ics")
cal = base.readOne(test_file)
dates = list(cal.vevent.getrruleset())
self.assertEqual(dates[0], datetime.datetime(2013, 1, 17, 0, 0))
self.assertEqual(dates[1], datetime.datetime(2013, 1, 24, 0, 0))
self.assertEqual(dates[-1], datetime.datetime(2013, 3, 28, 0, 0))

def test_recurrence_offset_naive(self):
"""
Ensure recurring vevent missing some time zone definitions is
parsing. See isseu #75.
"""
test_file = get_test_file("recurrence-offset-naive.ics")
cal = base.readOne(test_file)
dates = list(cal.vevent.getrruleset())
self.assertEqual(dates[0], datetime.datetime(2013, 1, 17, 0, 0))
self.assertEqual(dates[1], datetime.datetime(2013, 1, 24, 0, 0))
self.assertEqual(dates[-1], datetime.datetime(2013, 3, 28, 0, 0))


class TestChangeTZ(unittest.TestCase):
"""
Expand Down
6 changes: 5 additions & 1 deletion vobject/icalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -444,7 +444,11 @@ def getrruleset(self, addRDate=False):
# a Ruby iCalendar library escapes semi-colons in rrules,
# so also remove any backslashes
value = str_(line.value).replace('\\', '')
rule = rrule.rrulestr(value, dtstart=dtstart)
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 until is not None and isinstance(dtstart,
Expand Down

0 comments on commit b2fbdb2

Please sign in to comment.