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: expand all events that are active in the defined window #139

Merged
merged 1 commit into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
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
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)
Loading