Skip to content

Commit

Permalink
Merge pull request #139 from jazzband/fix/show-active-events
Browse files Browse the repository at this point in the history
fix: expand all events that are active in the defined window
  • Loading branch information
eigenmannmartin authored Sep 9, 2024
2 parents cefbd29 + 2495178 commit 8a68934
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
7 changes: 6 additions & 1 deletion icalevents/icalparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,12 @@ def is_not_exception(date):

if e.recurring:
rule = parse_rrule(component)
for dt in rule.between(f, t, inc=True):
# We can not use rule.between because the event has to fit in between https://github.com/jazzband/icalevents/issues/101
for dt in [
dt
for dt in list(rule.between(f - (end - start), t + (end - start)))
if dt >= f and dt <= t
]:
# Recompute the start time in the current timezone *on* the
# date of *this* occurrence. This handles the case where the
# recurrence has crossed over the daylight savings time boundary.
Expand Down
25 changes: 25 additions & 0 deletions test/test_data/recurring_small_window.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VTIMEZONE
TZID:Europe/Berlin
BEGIN:STANDARD
DTSTART:19701025T030000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=10
TZNAME:CET
TZOFFSETFROM:+0200
TZOFFSETTO:+0100
END:STANDARD
BEGIN:DAYLIGHT
DTSTART:19700329T020000
RRULE:FREQ=YEARLY;BYDAY=-1SU;BYMONTH=3
TZNAME:CEST
TZOFFSETFROM:+0100
TZOFFSETTO:+0200
END:DAYLIGHT
END:VTIMEZONE
BEGIN:VEVENT
DTSTART;TZID=Europe/Berlin:20211129T000000
DTEND;TZID=Europe/Berlin:20211129T080000
RRULE:FREQ=WEEKLY;UNTIL=20221230T230000Z;BYDAY=MO,TU,WE
END:VEVENT
END:VCALENDAR
13 changes: 13 additions & 0 deletions test/test_icalevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from dateutil.relativedelta import relativedelta
from dateutil.tz import UTC, gettz
from re import search
import textwrap
import pytz


Expand Down Expand Up @@ -932,3 +933,15 @@ def test_regression_repeating_events_raise_an_error(self):
"fourth event on 1. jan - 18. and 25. dec are excluded",
)
self.assertEqual(events[4].start, date(2024, 1, 8), "fifth event on 8. jan")

def test_regression_recurring_events_with_timezones(self):
# we need to test if all active events are returned, even if they do not fit fully in the defined window
tz = gettz("Europe/Berlin")
ical = "test/test_data/recurring_small_window.ics"
start = datetime(2022, 1, 11, 0, 0, 1, tzinfo=tz)
end = datetime(2022, 1, 11, 8, 0, 1, tzinfo=tz)

events = icalevents.events(file=ical, start=start, end=end, strict=True)

self.assertEqual(len(events), 1)
self.assertEqual(events[0].end.hour, 8)

0 comments on commit 8a68934

Please sign in to comment.