Ticket #20237 (new Bug)
Opened 14 months ago
toLocalizedTime does not handle Dexterity "Date" field type (datetime.date) values
Reported by: | trs22 | Owned by: | davisagli |
---|---|---|---|
Priority: | minor | Milestone: | 4.x |
Component: | Dexterity | Version: | 4.3 |
Keywords: | Cc: | trs22 |
Description
In Dexterity, there is a "Date/Time" field, which is stored as a Python "datetime.datetime" object, and a "Date" field, which is stored as a Python "datetime.date" object.
However, when calling "toLocalizedTime" in a page template, it returns an empty value for Dexterity Date/Python datetime.date fields. For example:
<span tal:content="python:toLocalizedTime(dexterity_date_field,long_format=0)">Dexterity Date Field</span>
It looks like it comes back to:
https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/i18nl10n.py#L149
where DateTime(time) (Zope DateTime) doesn't handle the datetime.date.
A simple fix to the Zope DateTime module that appears to work is:
*** ORIG-Datetime.py 2015-01-20 12:04:49.000000000 -0500 --- DateTime.py 2015-01-20 12:05:32.000000000 -0500 *************** *** 21,27 **** from time import time from time import timezone from time import tzname ! from datetime import datetime from pytz_support import PytzCache from zope.interface import implements --- 21,27 ---- from time import time from time import timezone from time import tzname ! from datetime import datetime, date from pytz_support import PytzCache from zope.interface import implements *************** *** 701,710 **** s, d = _calcSD(t) yr, mo, dy, hr, mn, sc, tz = arg.parts() ! elif isinstance(arg, datetime): yr, mo, dy, hr, mn, sc, numerictz, tznaive = \ self._parse_iso8601_preserving_tznaive(arg.isoformat()) ! if arg.tzinfo is None: self._timezone_naive = True tz = None else: --- 701,710 ---- s, d = _calcSD(t) yr, mo, dy, hr, mn, sc, tz = arg.parts() ! elif isinstance(arg, datetime) or isinstance(arg, date): yr, mo, dy, hr, mn, sc, numerictz, tznaive = \ self._parse_iso8601_preserving_tznaive(arg.isoformat()) ! if getattr(arg, 'tzinfo', None) is None: self._timezone_naive = True tz = None else:
although I'm not sure of any other ramifications of doing that.