collective / icalendar

icalendar parser library for Python

Home Page:https://icalendar.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to match dateuilts.rrule and python icalendar daylightsavingtime aware

Estartu opened this issue · comments

I'm dealing with some ical problems.

I have an ical event.

BEGIN:VEVENT
UID:Event/termine/gps/akt@portal.augusta.de 
DTSTART;TZID=CET:20150529T190000
DTEND;TZID=CET:20150529T220000
CATEGORIES:Arbeitsgruppe
DTSTAMP:20110620T075538Z
EXDATE;TZID=CET:20151225T190000
LAST-MODIFIED:20150424T201707Z
LOCATION:Vereinsräume des Augsburger Computer Forum e.V.
PRIORITY:5
RRULE:FREQ=MONTHLY;BYDAY=-1FR
SUMMARY:GPS-Arbeitsgruppe
URL:https://www.augusta.de/termine/gps
END:VEVENT

As you can see there is an RRule repeating this event every last friday of the month.

I parsed this ical with icalendar.

I'm using:

start = iobj.get( 'DTSTART' ).dt
rrset = rruleset()
rrule = iobj.get( 'RRULE' )
exdate = iobj.get( 'EXDATE' )
rrset.rrule( rrule.rrulestr( rule.to_ical(), dtstart = start ) )
for edate in exdate.dts : 
    rrset.exdate( edate.dt )

Everything so far works just fine.

When I Try to get the next say 10 dates with:

list(rrset)[:10] 

I get:

[datetime.datetime(2015, 5, 29, 19, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
 datetime.datetime(2015, 6, 26, 19, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
 datetime.datetime(2015, 7, 31, 19, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
 datetime.datetime(2015, 8, 28, 19, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
 datetime.datetime(2015, 9, 25, 19, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
 datetime.datetime(2015, 10, 30, 19, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
 datetime.datetime(2015, 11, 27, 19, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
 datetime.datetime(2015, 12, 25, 19, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
 datetime.datetime(2016, 1, 29, 19, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>),
 datetime.datetime(2016, 2, 26, 19, 0, tzinfo=<DstTzInfo 'CET' CEST+2:00:00 DST>)]

Which seems okay on the first glance, but on deeper inspection there is a problem starting with October 30th, daylight saving time ends October 25th but tzinfo info of the datetime object is still "DstTzInfo 'CET' CEST+2:00:00 DST"

The second problem is that the 25th of December is in this list instead of being skipped a specified in the EXDATE. The Problem seams to be tat while parsing the exdate rule daylight saving time is calculated correctly and therefore the exdate 19:00:00+01:00 didn't match the calculated repeat time of 19:00:00+02:00.

Am I doing something wrong there?

Converting everything to UTC and processing there doesn't help because 17:00:00 UTC don't match 18:00:00 UTC either.

This is not really an icalendar problem, more an issue with dateutil's rrule.

Have a look at this stackoverflow issue for a workaround.

Am 30.05.2015 11:18, schrieb Christian Geier:

This is not really an icalendar problem, more an issue with dateutil's
rrule.

Have a look at this stackoverflow issue
http://stackoverflow.com/questions/25715276/python-daylight-saving-time-issues/25725161#25725161
for a workaround.

This might work as long as all dates are in the same timezone. Having to
deal with date in one timezone but exdate in another will brake things
again.

I will send the problem to dateutil author as there seams to be no
isuetracker or mailingliste for.

Regards
Gerhard

dateutil development has picked up again, here at github:
https://github.com/dateutil/dateutil

Quoting Estartu (2015-05-30 12:10:19)

Am 30.05.2015 11:18, schrieb Christian Geier:

This is not really an icalendar problem, more an issue with dateutil's
rrule.

Have a look at this stackoverflow issue
http://stackoverflow.com/questions/25715276/python-daylight-saving-time-issues/25725161#25725161
for a workaround.

This might work as long as all dates are in the same timezone. Having to
deal with date in one timezone but exdate in another will brake things
again.

I will send the problem to dateutil author as there seams to be no
isuetracker or mailingliste for.

Regards
Gerhard


Reply to this email directly or view it on GitHub:
#162 (comment)

I'll reference dateutil/dateutil#641 here.

It seems pytz eager offset calculation causes this error. Icalendar could consider moving off pytz onto dateutil.tz or something else that handles Daylight savings better.

Looks sensible, we should put it onto the next major release schedule.