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: allow for non-recurring events with dates #140

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
21 changes: 12 additions & 9 deletions icalevents/icalparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,21 +360,24 @@ def is_not_exception(date):
e = create_event(component, strict)

# make rule.between happy and provide from, to points in time that have the same format as dtstart
s = component["dtstart"].dt
if type(s) is date and e.recurring == False:
f, t = start, end
elif type(s) is datetime and s.tzinfo:
if type(e.start) is date and e.recurring == False:
f, t = date(start.year, start.month, start.day), date(
end.year, end.month, end.day
)
elif type(e.start) is datetime and e.start.tzinfo:
f = (
datetime(
start.year,
start.month,
start.day,
start.hour,
start.minute,
tzinfo=s.tzinfo,
tzinfo=e.start.tzinfo,
)
if type(start) == datetime
else datetime(start.year, start.month, start.day, tzinfo=s.tzinfo)
else datetime(
start.year, start.month, start.day, tzinfo=e.start.tzinfo
)
)
t = (
datetime(
Expand All @@ -383,10 +386,10 @@ def is_not_exception(date):
end.day,
end.hour,
end.minute,
tzinfo=s.tzinfo,
tzinfo=e.start.tzinfo,
)
if type(end) == datetime
else datetime(end.year, end.month, end.day, tzinfo=s.tzinfo)
else datetime(end.year, end.month, end.day, tzinfo=e.start.tzinfo)
)
else:
f = (
Expand Down Expand Up @@ -421,7 +424,7 @@ def is_not_exception(date):
)
else:
ecopy = e.copy_to(
dt.date() if type(s) is date else dt, e.uid
dt.date() if type(e.start) is date else dt, e.uid
)
found.append(ecopy)

Expand Down
18 changes: 18 additions & 0 deletions test/test_data/regression_offset_native.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//6735d90b475eebfc9f111fc66f5e68fa//NONSGML kigkonsult.se iCalcreat
or 2.29.14//
CALSCALE:GREGORIAN
UID:84c4ae71-1eea-49fc-8e32-b551101c0b2d
X-WR-CALNAME:Company Holidays
BEGIN:VEVENT
UID:6200a801-f5f2-4c9d-a0a0-496f2691b19a
DTSTAMP:20200814T182712Z
CATEGORIES:Company Holidays
DESCRIPTION:Holiday (Jul 31)
DTSTART;VALUE=DATE:20200731
DTEND;VALUE=DATE:20200801
SUMMARY:Company Holiday - Studio Closure
TRANSP:TRANSPARENT
END:VEVENT
END:VCALENDAR
9 changes: 9 additions & 0 deletions test/test_icalevents.py
Original file line number Diff line number Diff line change
Expand Up @@ -945,3 +945,12 @@ def test_regression_recurring_events_with_timezones(self):

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

def test_regression_offset_aware_comparison(self):
ical = "test/test_data/regression_offset_native.ics"
start = datetime(2020, 7, 1)
end = datetime(2020, 7, 31)

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

self.assertEqual(len(events), 1)
Loading