Does dateutil rrule support DST and TZ? Need something similar to iCalendar RRULE.
If not – how to tackle this problem (scheduling recurring events & DST offset change)
Imports
>>> from django.utils import timezone
>>> import pytz
>>> from datetime import timedelta
>>> from dateutil import rrule
>>> now = timezone.now()
>>> pl = pytz.timezone("Europe/Warsaw")
Issue with timedelta (need to have the same local hours, but different DST offsets):
>>> pl.normalize(now)
datetime.datetime(2012, 9, 20, 1, 16, 58, 226000, tzinfo=<DstTzInfo 'Europe/Warsaw' CEST+2:00:00 DST>)
>>> pl.normalize(now+timedelta(days=180))
datetime.datetime(2013, 3, 19, 0, 16, 58, 226000, tzinfo=<DstTzInfo 'Europe/Warsaw' CET+1:00:00 STD>)
Issue with rrule (need to have the same every local hour of each occurrence):
>>> r = rrule.rrule(3,dtstart=now,interval=180,count=2)
>>> pl.normalize(r[0])
datetime.datetime(2012, 9, 20, 1, 16, 58, tzinfo=<DstTzInfo 'Europe/Warsaw' CEST+2:00:00 DST>)
>>> pl.normalize(r[1])
datetime.datetime(2013, 3, 19, 0, 16, 58, tzinfo=<DstTzInfo 'Europe/Warsaw' CET+1:00:00 STD>)
@asdf: I can’t add code to comments so I need to post this as an answer:
I am afraid that with your solution I will always loose DST info, therefore half of the year recurrences would be 1 hour off time.
Basing on your answer I found out that this might be the correct solution:
This is why I think your solution might fail:
As you can see, there is 1 hour difference between the rrule result, and the real data we store in the DB.