diff --git a/news/393.bugfix b/news/393.bugfix new file mode 100644 index 00000000..ab9396fa --- /dev/null +++ b/news/393.bugfix @@ -0,0 +1 @@ +Don't error out on 'Africa/Abidjan' timezone [gyst] diff --git a/plone/app/event/ical/exporter.py b/plone/app/event/ical/exporter.py index bd9f8156..f313903c 100644 --- a/plone/app/event/ical/exporter.py +++ b/plone/app/event/ical/exporter.py @@ -111,7 +111,6 @@ def add_to_zones_map(tzmap, tzid, dt): if tzid.lower() == "utc" or not is_datetime(dt): # no need to define UTC nor timezones for date objects. return tzmap - null = datetime(1, 1, 1) tz = pytz.timezone(tzid) transitions = getattr(tz, "_utc_transition_times", None) if not transitions: @@ -125,7 +124,7 @@ def add_to_zones_map(tzmap, tzid, dt): # datetime, which wouldn't create a match within the max-function. this # way we get the maximum transition time which is smaller than the # given datetime. - transition = max(transitions, key=lambda item: item if item <= dtzl else null) + transition = max(transitions, key=lambda item: item if item <= dtzl else dt.min) # get previous transition to calculate tzoffsetfrom idx = transitions.index(transition) @@ -133,10 +132,10 @@ def add_to_zones_map(tzmap, tzid, dt): prev_transition = transitions[prev_idx] def localize(tz, dt): - if dt is null: + if dt is datetime.min: # dummy time, edge case - # (dt at beginning of all transitions, see above.) - return null + # (dt at beginning of all transitions) + return dt.min return pytz.utc.localize(dt).astimezone(tz) # naive to utc + localize transition = localize(tz, transition) diff --git a/plone/app/event/tests/test_icalendar.py b/plone/app/event/tests/test_icalendar.py index c68e4ada..553434d7 100644 --- a/plone/app/event/tests/test_icalendar.py +++ b/plone/app/event/tests/test_icalendar.py @@ -1,6 +1,7 @@ from datetime import datetime from plone.app.event import base from plone.app.event.dx.traverser import OccurrenceTraverser as OccTravDX +from plone.app.event.ical.exporter import add_to_zones_map from plone.app.event.ical.importer import ical_import from plone.app.event.testing import make_fake_response from plone.app.event.testing import PAEventDX_FUNCTIONAL_TESTING @@ -499,3 +500,7 @@ def test_import_from_ics__sync_keep_theirs(self): self.assertNotEqual(desc21, desc22) self.assertTrue(start21 < start22) self.assertTrue(end21 < end22) + + def test_add_to_zones_map(self): + tzmap = add_to_zones_map({}, 'Africa/Abidjan', datetime(2013, 1, 1, 0, 0)) + self.assertTrue('Africa/Abidjan' in tzmap)