icalevents icon indicating copy to clipboard operation
icalevents copied to clipboard

Exception is thrown: can't compare offset-naive and offset-aware datetimes

Open thegrandpoobah opened this issue 4 years ago • 13 comments

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:

holidays.ics.txt

Any thoughts on this?

thegrandpoobah avatar Aug 17 '20 17:08 thegrandpoobah

@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?

Hultner avatar Aug 17 '20 17:08 Hultner

Hello, that doesn't work either. I will craft a working error case and create a repo for you.

thegrandpoobah avatar Aug 17 '20 18:08 thegrandpoobah

Here is the reproducible test case: https://github.com/thegrandpoobah/icalevents69

thegrandpoobah avatar Aug 19 '20 14:08 thegrandpoobah

Using Python 3.7.4 with icalevents 0.1.25 and icalendar 4.0.6

thegrandpoobah avatar Aug 19 '20 14:08 thegrandpoobah

@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!

kaitlynmcgoldrick avatar Aug 25 '20 19:08 kaitlynmcgoldrick

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.

nelson-liu avatar Sep 17 '20 07:09 nelson-liu

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)

test.ics.zip

daleiliu avatar Feb 28 '21 07:02 daleiliu

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')

timwoj avatar Jun 25 '21 20:06 timwoj

Still an issue, just installed via pip today. Using datetime objects as suggested.

jzohrab avatar May 24 '22 23:05 jzohrab

Is there any workaround for this? Can I modify the ics file to make it work for recurring all-day events?

dmirecki avatar May 27 '22 10:05 dmirecki

I've also just run into this bug and am trying to suss out how to work around it.

adamehirsch avatar Jul 17 '22 22:07 adamehirsch

Just had this problem (with a vCalendar generated by korganizer with an event from 2003)

cpina avatar Sep 30 '22 22:09 cpina

Hello, is there an update on this issue please? It's still there.

thanks! mic

berlingozzo avatar Jun 16 '23 17:06 berlingozzo

closed by: https://github.com/jazzband/icalevents/pull/140 thank you very much for the documentation and the example @thegrandpoobah

eigenmannmartin avatar Sep 09 '24 13:09 eigenmannmartin