Skip to content

Commit 45aaf61

Browse files
fix: allow for date exdates in ics #fixes 129
1 parent fb1f99c commit 45aaf61

File tree

3 files changed

+55
-5
lines changed

3 files changed

+55
-5
lines changed

icalevents/icalparser.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -362,10 +362,8 @@ def is_not_exception(date):
362362

363363
# make rule.between happy and provide from, to points in time that have the same format as dtstart
364364
s = component["dtstart"].dt
365-
if type(s) is date and not e.recurring:
366-
f, t = date(start.year, start.month, start.day), date(
367-
end.year, end.month, end.day
368-
)
365+
if type(s) is date and e.recurring == False:
366+
f, t = start, end
369367
elif type(s) is datetime and s.tzinfo:
370368
f, t = datetime(
371369
start.year, start.month, start.day, tzinfo=s.tzinfo
@@ -537,7 +535,12 @@ def conform_until(until, dtstart):
537535
# Add exdates to the rruleset
538536
for exd in extract_exdates(component):
539537
if type(dtstart) is date:
540-
rule.exdate(exd.replace(tzinfo=None))
538+
if type(exd) is date:
539+
# Always convert exdates to datetimes because rrule.between does not like dates
540+
# https://github.com/dateutil/dateutil/issues/938
541+
rule.exdate(datetime.combine(exd, datetime.min.time()))
542+
else:
543+
rule.exdate(exd.replace(tzinfo=None))
541544
else:
542545
rule.exdate(exd)
543546

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
BEGIN:VEVENT
2+
DTSTAMP:20231221T180428Z
3+
DTSTART;VALUE=DATE:20231127
4+
DTEND;VALUE=DATE:20231128
5+
SUMMARY:DSOC
6+
CATEGORIES:other
7+
SUBCALENDAR-ID:3dfdd9f8-dc5a-49b6-9b54-644138545076
8+
PARENT-CALENDAR-ID:f681d504-b5ed-4258-a68b-7deb867cf1bf
9+
PARENT-CALENDAR-NAME:
10+
SUBSCRIPTION-ID:
11+
SUBCALENDAR-TZ-ID:America/Los_Angeles
12+
SUBCALENDAR-NAME:My calendar
13+
EVENT-ID:163463
14+
EVENT-ALLDAY:true
15+
UID:20231012T192858Z--1042663660@my_org.com
16+
DESCRIPTION:
17+
ORGANIZER;X-CONFLUENCE-USER-KEY=09ceee004595a94a014595d847942220;CN=My Name;CUTYPE=INDIVIDUAL:mailto:[email protected]
18+
RRULE:FREQ=WEEKLY;UNTIL=20240115;INTERVAL=1;BYDAY=MO
19+
CREATED:20231012T192858Z
20+
LAST-MODIFIED:20231130T174704Z
21+
SEQUENCE:3
22+
X-CONFLUENCE-SUBCALENDAR-TYPE:other
23+
TRANSP:TRANSPARENT
24+
STATUS:CONFIRMED
25+
EXDATE;VALUE=DATE:20231225
26+
EXDATE;VALUE=DATE:20231218
27+
EXDATE;VALUE=DATE:20231225
28+
EXDATE;VALUE=DATE:20231218
29+
END:VEVENT

test/test_icalevents.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,3 +861,21 @@ def test_google_2024(self):
861861
5,
862862
"starts at 5 utc summer time (+2:00)",
863863
)
864+
865+
def test_regression_repeating_events_raise_an_error(self):
866+
ical = "test/test_data/recurrence_tzinfo.ics"
867+
start = date(2023, 1, 1)
868+
end = date(2024, 12, 31)
869+
870+
events = icalevents.events(file=ical, start=start, end=end, strict=True)
871+
872+
self.assertEqual(len(events), 6, "6 events")
873+
self.assertEqual(events[0].start, date(2023, 11, 27), "first on 27. nov")
874+
self.assertEqual(events[1].start, date(2023, 12, 4), "second event on 4. dec")
875+
self.assertEqual(events[2].start, date(2023, 12, 11), "third event on 11. dec")
876+
self.assertEqual(
877+
events[3].start,
878+
date(2024, 1, 1),
879+
"fourth event on 1. jan - 18. and 25. dec are excluded",
880+
)
881+
self.assertEqual(events[4].start, date(2024, 1, 8), "fifth event on 8. jan")

0 commit comments

Comments
 (0)