Skip to content

rrule _until missing timezone info #620

@jeinarsson

Description

@jeinarsson

I have a calendar (generated by Google) with a line like so:

RRULE:FREQ=MONTHLY;UNTIL=20180819;INTERVAL=12;BYDAY=3MO

If I use rrulestr to parse this recurrence with a dtstart including timezone info, the generator fails, because it tries a comparison with the _until field which has no timezone info.

Here's a minimal example of what I mean:

from datetime import datetime, timezone
from dateutil.rrule import *

rule_str = 'FREQ=MONTHLY;UNTIL=20180819;INTERVAL=12;BYDAY=3MO'

# this works (no timezone data)
start = datetime(2017,8,21)
rule = rrulestr(rule_str, dtstart=start)
print(list(rule))

# but this does not
start = datetime(2017,8,21,tzinfo=timezone.utc)
rule = rrulestr(rule_str, dtstart=start)
print(list(rule))

Output:

[datetime.datetime(2017, 8, 21, 0, 0)]
Traceback (most recent call last):
  File "mwe_rrule.py", line 17, in <module>
    print(list(rule))
  File "/usr/local/lib/python3.6/site-packages/dateutil/rrule.py", line 861, in _iter
    if until and res > until:
TypeError: can't compare offset-naive and offset-aware datetimes

EDIT: I monkey patched rrule.py after line 446:

until = datetime.datetime.fromordinal(until.toordinal())

by adding

        if until:
            until = until.replace(tzinfo=self._tzinfo)

If you're interested I could make a PR, but maybe you have a better way in mind.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions