diff options
author | Jason Madden <jason+github@nextthought.com> | 2017-12-18 11:19:26 -0600 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-12-18 11:19:26 -0600 |
commit | 57614e7d9bf7333dd404c553c43255a89a33d44d (patch) | |
tree | 28be553bba95493c5bde3f5c8bccfda8d25cd0d3 | |
parent | 01f04dd925d87e23dc49fab3d57d784f878c3d3a (diff) | |
parent | d9a21beddbd50d733f75d6507bda97d560baeca1 (diff) | |
download | zope-i18n-57614e7d9bf7333dd404c553c43255a89a33d44d.tar.gz |
Merge pull request #29 from zopefoundation/typeerror_on_time
Fix parsing times with a timezone
-rw-r--r-- | CHANGES.rst | 3 | ||||
-rw-r--r-- | src/zope/i18n/format.py | 7 | ||||
-rw-r--r-- | src/zope/i18n/tests/test_formats.py | 10 |
3 files changed, 9 insertions, 11 deletions
diff --git a/CHANGES.rst b/CHANGES.rst index 2015abb..265f7a2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -26,6 +26,9 @@ - Reach 100% test coverage and maintain in through tox.ini and coveralls.io. +- Fix parsing times with a timezone. Previously it could raise a + ``TypeError``. + 4.2.0 (2017-05-23) ================== diff --git a/src/zope/i18n/format.py b/src/zope/i18n/format.py index 5cb4d35..ee2e239 100644 --- a/src/zope/i18n/format.py +++ b/src/zope/i18n/format.py @@ -181,11 +181,10 @@ class DateTimeFormat(object): return datetime.date(*[e or 0 for e in ordered[:3]]) if ordered[:3] == [None, None, None]: if pytz_tzinfo: - # XXX: This raises a TypeError: - # unsupported operator + for datetime.time and datetime.timedelta return tzinfo.localize( - datetime.time(*[e or 0 for e in ordered[3:]]) - ) + datetime.datetime.combine( + datetime.date.today(), + datetime.time(*[e or 0 for e in ordered[3:]]))).timetz() return datetime.time( *[e or 0 for e in ordered[3:]], **{'tzinfo' :tzinfo} ) diff --git a/src/zope/i18n/tests/test_formats.py b/src/zope/i18n/tests/test_formats.py index 8e52e6d..99c4bf7 100644 --- a/src/zope/i18n/tests/test_formats.py +++ b/src/zope/i18n/tests/test_formats.py @@ -422,16 +422,12 @@ class TestDateTimeFormat(_TestCase): 'HH:mm:ss zzzz')) def testParsePyTzTimezone(self): - # XXX: Bug: This raises - # TypeError: unsupported operand type(s) for +: 'datetime.time' and 'datetime.timedelta' - # at pytz/tzinfo.py:309 - # (PyPy and CPython produce slightly different error messages; - # PyPy doesn't include the modulename) tzinfo = pytz.timezone("US/Central") - with self.assertRaisesRegex(TypeError, 'timedelta'): + self.assertEqual( + datetime.time(21, 48, 1, tzinfo=tzinfo), self.format.parse( '21:48:01 US/Central', - 'HH:mm:ss zzzz') + 'HH:mm:ss zzzz')) def testFormatSimpleDateTime(self): # German short |