icalevents
icalevents copied to clipboard
Exception is thrown: can't compare offset-naive and offset-aware datetimes
Hello, I am trying to use the icalevents library to parse a iCal feed generated by Bamboo HR for our company time offs.
Here is the code that I am using:
evs = events(url=url, start=date(2020, 9, 1), end=date(2020, 9, 30))
for event in evs:
print(event)
This throws the following error:
File "/home/sahab/anaconda3/lib/python3.7/site-packages/icalevents/icalparser.py", line 91, in __str__
if self.end > n > self.start:
TypeError: can't compare offset-naive and offset-aware datetimes
Not sure if I'm doing something wrong, if the iCal is malformed for whatever reason, or if there is a bug in the library, but I've attached the calendar in question to start:
Any thoughts on this?
@thegrandpoobah What happens if you use datetime
-objects instead of date
-objects?
Changing your example code to
from datetime import datetime
evs = events(url=url, start=datetime(2020, 9, 1), end=datetime(2020, 9, 30))
for event in evs:
print(event)
If that doesn't work do you think you could provide a full runnable example?
Hello, that doesn't work either. I will craft a working error case and create a repo for you.
Here is the reproducible test case: https://github.com/thegrandpoobah/icalevents69
Using Python 3.7.4 with icalevents 0.1.25 and icalendar 4.0.6
@Hultner I made a PR for this issue, it's a quick fix so I'm open to feedback on the solution. PTAL, thank you!
This also occurs with a recurring, all-day events. Things are coerced to naive timezones here https://github.com/irgangla/icalevents/blob/master/icalevents/icalparser.py#L304-L315 , but the rule.between
here https://github.com/irgangla/icalevents/blob/master/icalevents/icalparser.py#L356 fails because after is time-zone naive, whereas the values in rules._exdate
are not timezone naive.
I have a similar issue when try this code against the attached google calendar generated ics file:
from icalevents import icalevents
from datetime import date, timedelta, datetime
ical = "test.ics"
start = datetime(2021, 2, 20)
end = datetime(2021, 2, 21)
evs = icalevents.events(file=ical, start=start, end=end)
I don't think the PR linked here is a complete fix unfortunately. I'm still running into the exception even after installing the latest commit via pip. The test file that @daleiliu linked above reproduces it still, doing nothing more than:
from icalevents import icalevents
evs = icalevents.events(file='test.ics')
Still an issue, just installed via pip today. Using datetime objects as suggested.
Is there any workaround for this? Can I modify the ics file to make it work for recurring all-day events?
I've also just run into this bug and am trying to suss out how to work around it.
Just had this problem (with a vCalendar generated by korganizer with an event from 2003)
Hello, is there an update on this issue please? It's still there.
thanks! mic
closed by: https://github.com/jazzband/icalevents/pull/140 thank you very much for the documentation and the example @thegrandpoobah