Commit cd043373 authored by Laurence Rowe's avatar Laurence Rowe

DateTime conversion of datetime objects with non-pytz tzinfo.

        Timezones() returns a copy of the timezone list (allows tests to run).
        (Backport of r89373 from trunk).
parent 40aa6ab3
...@@ -8,6 +8,10 @@ Zope Changes ...@@ -8,6 +8,10 @@ Zope Changes
Bugs Fixed Bugs Fixed
- DateTime conversion of datetime objects with non-pytz tzinfo.
Timezones() returns a copy of the timezone list (allows tests to run).
(Backport of r89373 from trunk).
- LP #253362: better dealing with malformed HTTP_ACCEPT_CHARSET headers - LP #253362: better dealing with malformed HTTP_ACCEPT_CHARSET headers
......
...@@ -599,7 +599,8 @@ class DateTime: ...@@ -599,7 +599,8 @@ class DateTime:
tz = None tz = None
else: else:
self._timezone_naive = False self._timezone_naive = False
tz = arg.tzinfo.zone # if we have a pytz tzinfo, use the `zone` attribute as a key
tz = getattr(arg.tzinfo, 'zone', numerictz)
ms = sc - math.floor(sc) ms = sc - math.floor(sc)
x = _calcDependentSecond2(yr,mo,dy,hr,mn,sc) x = _calcDependentSecond2(yr,mo,dy,hr,mn,sc)
...@@ -1850,5 +1851,5 @@ class strftimeFormatter: ...@@ -1850,5 +1851,5 @@ class strftimeFormatter:
# Module methods # Module methods
def Timezones(): def Timezones():
"""Return the list of recognized timezone names""" """Return the list of recognized timezone names"""
return PytzCache._zlst return list(PytzCache._zlst)
...@@ -19,7 +19,7 @@ import unittest ...@@ -19,7 +19,7 @@ import unittest
from DateTime.DateTime import _findLocalTimeZoneName, _cache from DateTime.DateTime import _findLocalTimeZoneName, _cache
from DateTime import DateTime from DateTime import DateTime
from datetime import datetime from datetime import datetime, tzinfo, timedelta
import pytz import pytz
import legacy import legacy
...@@ -34,6 +34,24 @@ else: ...@@ -34,6 +34,24 @@ else:
DATADIR = os.path.dirname(os.path.abspath(f)) DATADIR = os.path.dirname(os.path.abspath(f))
del f del f
ZERO = timedelta(0)
class FixedOffset(tzinfo):
"""Fixed offset in minutes east from UTC."""
def __init__(self, offset, name):
self.__offset = timedelta(minutes = offset)
self.__name = name
def utcoffset(self, dt):
return self.__offset
def tzname(self, dt):
return self.__name
def dst(self, dt):
return ZERO
class DateTimeTests(unittest.TestCase): class DateTimeTests(unittest.TestCase):
...@@ -561,8 +579,17 @@ class DateTimeTests(unittest.TestCase): ...@@ -561,8 +579,17 @@ class DateTimeTests(unittest.TestCase):
real_failures = list(set(failures).difference(set(expected_failures))) real_failures = list(set(failures).difference(set(expected_failures)))
self.failIf(real_failures, '\n'.join(real_failures)) self.failIf(real_failures, '\n'.join(real_failures))
def testBasicTZ(self):
"""psycopg2 supplies it's own tzinfo instances, with no `zone` attribute
"""
tz = FixedOffset(60, 'GMT+1')
dt1 = datetime(2008, 8, 5, 12, 0, tzinfo=tz)
DT = DateTime(dt1)
dt2 = DT.asdatetime()
offset1 = dt1.tzinfo.utcoffset(dt1)
offset2 = dt2.tzinfo.utcoffset(dt2)
self.assertEqual(offset1, offset2)
def test_suite(): def test_suite():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment