Commit ca3cfdaa 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).
parent 98305443
......@@ -204,6 +204,9 @@ Zope Changes
Bugs Fixed
- DateTime conversion of datetime objects with non-pytz tzinfo.
Timezones() returns a copy of the timezone list (allows tests to run).
- LP #253362: better dealing with malformed HTTP_ACCEPT_CHARSET headers
- Launchpad #246748: added 'immediate' option to sendXXX() methods
......
......@@ -599,7 +599,8 @@ class DateTime:
tz = None
else:
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)
x = _calcDependentSecond2(yr,mo,dy,hr,mn,sc)
......@@ -1850,5 +1851,5 @@ class strftimeFormatter:
# Module methods
def Timezones():
"""Return the list of recognized timezone names"""
return PytzCache._zlst
return list(PytzCache._zlst)
......@@ -19,7 +19,7 @@ import unittest
from DateTime.DateTime import _findLocalTimeZoneName, _cache
from DateTime import DateTime
from datetime import datetime
from datetime import datetime, tzinfo, timedelta
import pytz
import legacy
......@@ -34,6 +34,24 @@ else:
DATADIR = os.path.dirname(os.path.abspath(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):
......@@ -562,7 +580,16 @@ class DateTimeTests(unittest.TestCase):
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():
......
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