Skip to content

Big bad DateTime bug workaround for correct ulocalized_time() timezone support #47

Merged
merged 3 commits into from Aug 22, 2012
View
21 plone/app/event/base.py
@@ -1,6 +1,8 @@
import pytz
from DateTime import DateTime
from Products.CMFCore.utils import getToolByName
+from Products.CMFPlone import i18nl10n
+from Products.CMFPlone.i18nl10n import ulocalized_time as orig_ulocalized_time
from datetime import date
from datetime import datetime
from datetime import timedelta
@@ -192,10 +194,10 @@ def DT(dt):
@param dt: python datetime instance
"""
-
tz = default_timezone(getSite())
if isinstance(dt, datetime):
- tz = validated_timezone(dt.tzname(), tz)
+ zone_id = getattr(dt.tzinfo, 'zone', tz)
+ tz = validated_timezone(zone_id, tz)
return DateTime(dt.year, dt.month, dt.day,\
dt.hour, dt.minute, dt.second, tz)
elif isinstance(dt, date):
@@ -248,3 +250,18 @@ def guess_date_from(datestr, context=None):
return
return pytz.timezone(default_timezone(context)).localize(dateobj)
+
+
+_strftime = lambda v, fmt: pydt(v).strftime(fmt)
+
+
+class PatchedDateTime(DateTime):
+
+ def strftime(self, fmt):
+ return _strftime(self, fmt)
+
+
+def ulocalized_time(time, *args, **kwargs):
+ """Corrects for DateTime bugs doing wrong thing with timezones"""
+ wrapped_time = PatchedDateTime(time)
+ return orig_ulocalized_time(wrapped_time, *args, **kwargs)
View
3 plone/app/event/browser/event_view.py
@@ -1,9 +1,8 @@
-from Products.CMFPlone.i18nl10n import ulocalized_time
from Products.Five.browser import BrowserView
from plone.event.interfaces import IEventAccessor, IRecurrenceSupport
from plone.event.utils import is_same_day, is_same_time
-from plone.app.event.base import DT
+from plone.app.event.base import DT, ulocalized_time
def prepare_for_display(context, start, end, whole_day):
View
2 plone/app/event/tests/test_atevent_integration.py
@@ -24,7 +24,7 @@ def test_event_accessor(self):
e1 = self.portal['event1']
# setting attributes via the accessor
- import pdb; pdb.set_trace()
+ #import pdb; pdb.set_trace()
acc = IEventAccessor(e1)
acc.end = datetime(2011,11,13,10,0)
acc.timezone = 'CET'
Something went wrong with that request. Please try again.