4

I've been trying to parse recurrence rules using python's dateutil rrule package

However, I am getting an odd error inconsistent with the way I understand recurrence rules

The error is

ValueError: RRULE UNTIL values must be specified in UTC when DTSTART is timezone-aware

The function I'm calling is

recurrence = "RRULE:FREQ=WEEKLY;UNTIL=20181206T075959Z;BYDAY=MO,WE,FR" rule = rrulestr(recurrence, dtstart=datetime.now())

If the until is structured as UNTIL=20181206T075959Z, isn't that in UTC? Why would this error show up, and what is an appropriate solution? The thing is, this works with

"RRULE:FREQ=WEEKLY;UNTIL=20191206T075959;BYDAY=MO,WE,FR", which I thought was not in UTC, because it was missing the 'Z'

rma
  • 1,853
  • 1
  • 22
  • 42

1 Answers1

7

This may be a confusing error message because it is taken from the RFC spec but doesn't really explain the context.

The problem is that dtstart and UNTIL must both either be naive or timezone-aware, and the spec actually specifies that UNTIL has to be UTC specifically in that case.

To fix your code, you can just make dtstart timezone-aware:

from dateutil.tz import UTC
recurrence = "RRULE:FREQ=WEEKLY;UNTIL=20181206T075959Z;BYDAY=MO,WE,FR"
rule = rrulestr(recurrence, dtstart=datetime.now(UTC))

Feel free to report the confusing error message on dateutil's issue tracker.

Paul
  • 10,381
  • 13
  • 48
  • 86