Skip to content

Commit

Permalink
Merge branch 'master' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
jensens authored Jun 10, 2024
2 parents 73cd7ee + f19939d commit dd89dd6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@ Changelog
.. towncrier release notes start
5.1.4 (2024-06-07)
------------------

Bug fixes:


- Don't error out on 'Africa/Abidjan' timezone [gyst] (#393)


5.1.3 (2024-05-30)
------------------

Expand Down
9 changes: 4 additions & 5 deletions plone/app/event/ical/exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -125,18 +124,18 @@ 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)
prev_idx = idx - 1 if idx > 0 else idx
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)
Expand Down
5 changes: 5 additions & 0 deletions plone/app/event/tests/test_icalendar.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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)
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from setuptools import setup


version = "5.1.4.dev0"
version = "5.1.5.dev0"


long_description = "\n\n".join(
Expand Down

0 comments on commit dd89dd6

Please sign in to comment.