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

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

Closed
thegrandpoobah opened this issue Aug 17, 2020 · 14 comments · Fixed by #140
Closed

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

thegrandpoobah opened this issue Aug 17, 2020 · 14 comments · Fixed by #140

Comments

@thegrandpoobah
Copy link

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?

@Hultner
Copy link
Member

Hultner commented Aug 17, 2020

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

@thegrandpoobah
Copy link
Author

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

@thegrandpoobah
Copy link
Author

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

@thegrandpoobah
Copy link
Author

Using Python 3.7.4 with icalevents 0.1.25 and icalendar 4.0.6

@kaitlynmcgoldrick
Copy link
Contributor

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

@nelson-liu
Copy link

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.

@daleiliu
Copy link

daleiliu commented Feb 28, 2021

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

@timwoj
Copy link

timwoj commented Jun 25, 2021

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

@jzohrab
Copy link

jzohrab commented May 24, 2022

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

@dmirecki
Copy link

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

@adamehirsch
Copy link

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

@cpina
Copy link

cpina commented Sep 30, 2022

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

@berlingozzo
Copy link

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

thanks!
mic

@eigenmannmartin
Copy link
Member

closed by: #140 thank you very much for the documentation and the example @thegrandpoobah

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.