Skip to content

Commit ff44d17

Browse files
author
Thomas Irgang
authored
Merge pull request #49 from tdaff/rrule-until
Convert RRULE UNTIL with no tzinfo to UTC
2 parents 5716e64 + 062fb93 commit ff44d17

3 files changed

Lines changed: 40 additions & 0 deletions

File tree

icalevents/icalparser.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,15 @@ def parse_rrule(component, tz=UTC):
259259
rrules = component['rrule']
260260
if not isinstance(rrules, list):
261261
rrules = [rrules]
262+
263+
# Since DTSTART are always made timezone aware, UNTIL with no tzinfo
264+
# must be converted to UTC.
265+
for rule in rrules:
266+
until = rule.get("until")
267+
for idx, dt in enumerate(until or []):
268+
if not hasattr(dt, 'tzinfo'):
269+
until[idx] = normalize(normalize(dt, tz=tz), tz=UTC)
270+
262271
# Parse the rrules, might return a rruleset instance, instead of rrule
263272
rule = rrulestr('\n'.join(x.to_ical().decode() for x in rrules), dtstart=normalize(component['dtstart'].dt, tz=tz))
264273

test/test_data/rrule_until.ics

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
BEGIN:VCALENDAR
2+
BEGIN:VTIMEZONE
3+
TZID:Europe/Berlin
4+
END:VTIMEZONE
5+
BEGIN:VEVENT
6+
DTSTART;VALUE=DATE:20151030
7+
DTEND;VALUE=DATE:20151031
8+
DESCRIPTION:All-day event recurring on tuesday each week
9+
SUMMARY:Recurring All-day Event
10+
RRULE:FREQ=WEEKLY;BYDAY=TU;UNTIL=20341031
11+
END:VEVENT
12+
BEGIN:VEVENT
13+
DTSTART;TZID=Europe/London:20180522T120000
14+
DTEND;TZID=Europe/London:20180522T130000
15+
DESCRIPTION:Daily lunchtime event with specified hours
16+
SUMMARY:Daily lunch event
17+
RRULE:FREQ=DAILY;UNTIL=20330523T060000Z
18+
END:VEVENT
19+
END:VCALENDAR

test/test_icalevents.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,18 @@ def test_events_all_day_recurring(self):
107107
self.assertEqual(ev_2.description, "All-day event recurring on tuesday each week")
108108
self.assertTrue(ev_2.all_day, "Recurring All-day Event's second instance is an all-day event")
109109

110+
def test_events_rrule_until(self):
111+
ical = "test/test_data/rrule_until.ics"
112+
start = date(2019, 4, 2)
113+
end = date(2019, 4, 3)
114+
115+
evs = icalevents.events(file=ical, start=start, end=end)
116+
117+
self.assertEqual(len(evs), 2)
118+
self.assertEqual(evs[0].recurring, True)
119+
self.assertEqual(evs[0].summary, "Recurring All-day Event")
120+
self.assertEqual(evs[1].recurring, True)
121+
self.assertEqual(evs[1].summary, "Daily lunch event")
110122

111123
def test_event_attributes(self):
112124
ical = "test/test_data/basic.ics"

0 commit comments

Comments
 (0)