Skip to content

Commit

Permalink
[round_robin_calendar] Handle recurring events (#1976)
Browse files Browse the repository at this point in the history
  • Loading branch information
suhaibmujahid committed Apr 11, 2023
1 parent 0b8eead commit 941e19a
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
12 changes: 0 additions & 12 deletions auto_nag/round_robin_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,6 @@ def get(url, fallback, team_name, people=None):
return JSONCalendar(cal, fallback, team_name, people=people)
except JSONDecodeError:
try:
# there is an issue with dateutil.rrule parser when until doesn't have a tz
# so a workaround is to add a Z at the end of the string.
pat = re.compile(r"^RRULE:(.*)UNTIL=([0-9Z]+)", re.MULTILINE | re.I)

def sub(m):
date = m.group(1)
if date.lower().endswith("z"):
return date
return date + "Z"

data = pat.sub(sub, data)

return ICSCalendar(data, fallback, team_name, people=people)
except ValueError:
raise InvalidCalendar(
Expand Down
21 changes: 21 additions & 0 deletions auto_nag/tests/data/calendar_recurring.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
BEGIN:VCALENDAR
PRODID:-//Google Inc//Google Calendar 70.9054//EN
VERSION:2.0
CALSCALE:GREGORIAN
METHOD:PUBLISH
BEGIN:VEVENT
DTSTART;VALUE=DATE:20221201
DTEND;VALUE=DATE:20221215
RRULE:FREQ=WEEKLY;UNTIL=20230517;INTERVAL=12;BYDAY=TH
DTSTAMP:20230228T170245Z
UID:7m8qpj9kbo8jcdk0lc576fdrh8@google.com
CREATED:20221026T152624Z
DESCRIPTION:
LAST-MODIFIED:20230224T192109Z
LOCATION:
SEQUENCE:0
STATUS:CONFIRMED
SUMMARY:Gregory Mierzwinski
TRANSP:TRANSPARENT
END:VEVENT
END:VCALENDAR
19 changes: 19 additions & 0 deletions auto_nag/tests/test_calendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,28 @@ def test_performance_tools_calendar(self):
people=People([]),
)

self.assertEqual(
calendar.get_persons("2023-02-28"), [("Gregory Mierzwinski", None)]
)
self.assertEqual(calendar.get_persons("2023-03-09"), [("Kash Shampur", None)])
self.assertEqual(calendar.get_persons("2023-03-22"), [("Kash Shampur", None)])
self.assertEqual(
calendar.get_persons("2023-03-30"), [("Alexandru Ionescu", None)]
)
self.assertEqual(calendar.get_persons("2023-04-20"), [("Andrej Glavic", None)])

def test_recurring_event(self):
"""Test a calendar with a recurring event."""
calendar = ICSCalendar.get(
"auto_nag/tests/data/calendar_recurring.ics",
"recurring@mozilla.tld",
"recurring",
people=People([]),
)

self.assertEqual(
calendar.get_persons("2022-12-01"), [("Gregory Mierzwinski", None)]
)
self.assertEqual(
calendar.get_persons("2023-02-28"), [("Gregory Mierzwinski", None)]
)

0 comments on commit 941e19a

Please sign in to comment.