Log message for revision 89373: DateTime conversion of datetime objects with non-pytz tzinfo. Timezones() returns a copy of the timezone list (allows tests to run).
Changed: U Zope/trunk/doc/CHANGES.txt U Zope/trunk/lib/python/DateTime/DateTime.py U Zope/trunk/lib/python/DateTime/tests/testDateTime.py -=- Modified: Zope/trunk/doc/CHANGES.txt =================================================================== --- Zope/trunk/doc/CHANGES.txt 2008-08-05 11:34:49 UTC (rev 89372) +++ Zope/trunk/doc/CHANGES.txt 2008-08-05 11:49:40 UTC (rev 89373) @@ -204,6 +204,9 @@ 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 Modified: Zope/trunk/lib/python/DateTime/DateTime.py =================================================================== --- Zope/trunk/lib/python/DateTime/DateTime.py 2008-08-05 11:34:49 UTC (rev 89372) +++ Zope/trunk/lib/python/DateTime/DateTime.py 2008-08-05 11:49:40 UTC (rev 89373) @@ -599,7 +599,8 @@ 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 @@ # Module methods def Timezones(): """Return the list of recognized timezone names""" - return PytzCache._zlst + return list(PytzCache._zlst) Modified: Zope/trunk/lib/python/DateTime/tests/testDateTime.py =================================================================== --- Zope/trunk/lib/python/DateTime/tests/testDateTime.py 2008-08-05 11:34:49 UTC (rev 89372) +++ Zope/trunk/lib/python/DateTime/tests/testDateTime.py 2008-08-05 11:49:40 UTC (rev 89373) @@ -19,7 +19,7 @@ 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,7 +34,25 @@ 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): def _compare(self, dt1, dt2, ms=1): @@ -561,8 +579,17 @@ real_failures = list(set(failures).difference(set(expected_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(): _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins