[Zope3-dev] Failing test, Zope3 trunk, Windows

Stuart Bishop stuart at stuartbishop.net
Wed Sep 7 01:09:30 EDT 2005


Tim Peters wrote:
> Not sure when this started to fail -- "recently":
> 
> Failure in test testParseTimeZoneNames
> (zope.i18n.tests.test_formats.TestDateTimeFormat)
> Traceback (most recent call last):
>   File "C:\Code\Zope3\src\zope\i18n\tests\test_formats.py", line 306,
> in testParseTimeZoneNames
>     self.assertEqual(dt.tzinfo.utcoffset(dt), datetime.timedelta(hours=-6))
>   File "C:\python23\lib\unittest.py", line 302, in failUnlessEqual
>     raise self.failureException, \
> AssertionError: datetime.timedelta(-1, 67200) != datetime.timedelta(-1, 64800)
> 
> 
> Not sure what the test case is testing either:
> 
>     def testParseTimeZoneNames(self):
>         dt = self.format.parse('01.01.2003 09:48 EST', 'dd.MM.yyyy HH:mm zzz')
>         self.assertEqual(dt.tzinfo.utcoffset(dt), datetime.timedelta(hours=-6))
> 
> EST is 5 hours west of UTC, so I'm not sure why -6 would be expected. 
> The minus 5 hours and 20 minutes it's getting back doesn't seem right
> either ;-)

Actually, EST is 5 hours west of UTC, and 10 hours east of UTC, and 11 hours
east of UTC.

What was happening is that self.format.parse() is constructing a localtime
datetime instance without invoking the pytz localize() method to bind the
correct timezone information (as documented in the pytz README.txt and on
http://pytz.sourceforge.net )

So the new Olson release says that Eastern Standard Time only started being
UTC-0500 in 1908, and prior to that people actually thought noon was when
the sun was directly overhead (UTC-0520). When the datetime is constructed
in a local timezone (rather than converted from UTC), you get arbitrary
tzinfo information because no pytz code is invoked so no calculations can be
done to determine the correct timezone information to use for that datetime.
The localize() method is a workaround for this. I really need to knock up a
PEP detailing the hooks required in the datetime library to get this all
working seemlessly so I can deprecate localize() and normalize() from pytz.

Anyway - I've fixed the broken code and updated the tests. My fault for not
running the tests - most of my time is spent with a system that runs the
tests for me before accepting my commit and my brain had not fully context
switched.

-- 
Stuart Bishop <stuart at stuartbishop.net>
http://www.stuartbishop.net/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: OpenPGP digital signature
Url : http://mail.zope.org/pipermail/zope3-dev/attachments/20050907/a8912890/signature-0001.bin


More information about the Zope3-dev mailing list