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

RRULE: Gracefully handle offset-naive and offset-aware datetimes #75

Closed
htgoebel opened this issue May 24, 2017 · 1 comment
Closed
Milestone

Comments

@htgoebel
Copy link
Contributor

The following code fails with TypeError: can't compare offset-naive and offset-aware datetimes.

event = """
BEGIN:VCALENDAR
VERSION:2.0
BEGIN:VEVENT
DTSTART;VALUE=DATE:20130117
DTEND;VALUE=DATE:20130118
RRULE:FREQ=WEEKLY;UNTIL=20130330T230000Z;BYDAY=TH
SUMMARY:Meeting
END:VEVENT
END:VCALENDAR
""".strip()

import vobject

ev = vobject.readOne(event).vevent
ev.getrruleset(addRDate=True)

Traceback:

  File "…/site-packages/vobject/icalendar.py", line 501, in getrruleset
    if rruleset._rrule[-1][0] != adddtstart:
  File "…site-packages/dateutil/rrule.py", line 159, in __getitem__
    res = advance_iterator(gen)
  File "…/site-packages/dateutil/rrule.py", line 860, in _iter
    if until and res > until:
TypeError: can't compare offset-naive and offset-aware datetimes

Actual values are:

  • res = datetime.datetime(2013, 1, 17, 0, 0) from DTSTART;VALUE=DATE:20130117
  • until = datetime.datetime(2013, 3, 30, 23, 0, tzinfo=tzutc()) from RRULE:FREQ=WEEKLY;UNTIL=20130330T230000Z;BYDAY=TH
@htgoebel
Copy link
Contributor Author

The cause of this problem seems to be at icalendar line 447:

rule = rrule.rrulestr(value, dtstart=dtstart)
until = rule._until

If dtstart has no timezone, util will have a time-zone (utc) (see below).

Just behind this place there is code handling the case that until.tzinfo != dtstart.tzinfo, but only if isinstance(dtstart, datetime.datetime). I assume the case isinstance(dtstart, datetime.date). needs to be handled here, too.

Insights from my debugging-session:

> …/site-packages/vobject/icalendar.py(447)getrruleset()
-> rule = rrule.rrulestr(value, dtstart=dtstart)
(Pdb) n
> …/site-packages/vobject/icalendar.py(448)getrruleset()
-> until = rule._until
(Pdb) p dtstart
datetime.date(2013, 1, 17)
(Pdb) p until
datetime.datetime(2013, 3, 30, 23, 0, tzinfo=tzutc())
(Pdb) p rule._tzinfo
None
(Pdb) p until.tzinfo
tzutc()

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

No branches or pull requests

2 participants