Correct the handling of rrules within timezone definitions.

Fix for https://github.com/collective/icalendar/issues/303
pull/320/head
Simon Budig 2020-02-13 19:09:54 +01:00 zatwierdzone przez Johannes Raggam
rodzic 8047148a7b
commit 2a82c88c65
3 zmienionych plików z 15 dodań i 12 usunięć

Wyświetl plik

@ -14,7 +14,7 @@ New features:
Bug fixes:
- *add item here*
- fixed rrule handling, re-enabled test_create_america_new_york()
4.0.6 (2020-05-06)

Wyświetl plik

@ -17,7 +17,7 @@ from icalendar.prop import vText, vDDDLists
from icalendar.timezone_cache import _timezone_cache
import pytz
import dateutil.rrule
import dateutil.rrule, dateutil.tz
from pytz.tzinfo import DstTzInfo
from icalendar.compat import unicode_type
@ -536,15 +536,23 @@ class Timezone(Component):
# expand recurrences
if 'RRULE' in component:
# to be paranoid about correct weekdays
# evaluate the rrule with the current offset
tzi = dateutil.tz.tzoffset ("(offsetfrom)", offsetfrom)
rrstart = dtstart.replace (tzinfo=tzi)
rrulestr = component['RRULE'].to_ical().decode('utf-8')
rrule = dateutil.rrule.rrulestr(rrulestr, dtstart=dtstart)
rrule = dateutil.rrule.rrulestr(rrulestr, dtstart=rrstart)
if not {'UNTIL', 'COUNT'}.intersection(component['RRULE'].keys()):
# pytz.timezones don't know any transition dates after 2038
# either
rrule._until = datetime(2038, 12, 31)
elif 'UNTIL' in component['RRULE'] and rrule._until.tzinfo:
rrule._until = rrule._until.replace(tzinfo=None)
transtimes = rrule
rrule._until = datetime(2038, 12, 31, tzinfo=pytz.UTC)
# constructing the pytz-timezone requires UTC transition times.
# here we construct local times without tzinfo, the offset to UTC
# gets subtracted in to_tz().
transtimes = [dt.replace (tzinfo=None) for dt in rrule]
# or rdates
elif 'RDATE' in component:
if not isinstance(component['RDATE'], list):

Wyświetl plik

@ -149,14 +149,9 @@ class TestTimezoned(unittest.TestCase):
class TestTimezoneCreation(unittest.TestCase):
@unittest.expectedFailure
def test_create_america_new_york(self):
"""testing America/New_York, the most complex example from the
RFC"""
# FIXME
# This currently fails because of mixed naive and timezone
# aware datetimes in dtstart and until which breaks
# dateutil recurrence.
directory = os.path.dirname(__file__)
with open(os.path.join(directory, 'america_new_york.ics'), 'rb') as fp: