Mercurial > babel > old > babel-test
changeset 511:f2098e9c05b4 stable-0.9.x
Fix bad check in format_time (closes #257), reported with patch and tests by jomae
author | fschwarz |
---|---|
date | Fri, 04 Mar 2011 22:34:14 +0000 |
parents | d877836a8455 |
children | f46bdfd4a333 |
files | ChangeLog babel/dates.py babel/tests/dates.py |
diffstat | 3 files changed, 24 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -25,6 +25,8 @@ * Small speed improvement in format_date() (ticket #216). * Fix number formatting for locales where CLDR specifies alt or draft items (ticket #217) + * Fix bad check in format_time (ticket #257, reported with patch and tests by + jomae) Version 0.9.5
--- a/babel/dates.py +++ b/babel/dates.py @@ -578,7 +578,7 @@ if isinstance(time, datetime): if tzinfo is not None: time = time.astimezone(tzinfo) - if hasattr(tzinfo, 'localize'): # pytz + if hasattr(tzinfo, 'normalize'): # pytz time = tzinfo.normalize(time) time = time.timetz() elif tzinfo is not None:
--- a/babel/tests/dates.py +++ b/babel/tests/dates.py @@ -13,11 +13,13 @@ from datetime import date, datetime, time import doctest +import new import unittest from pytz import timezone from babel import dates +from babel.util import FixedOffsetTimezone class DateTimeFormatTestCase(unittest.TestCase): @@ -247,12 +249,31 @@ "yyyy-MM-dd HH:mm", locale='en_US') +class TimeZoneAdjustTestCase(unittest.TestCase): + def _utc(self): + UTC = FixedOffsetTimezone(0, 'UTC') + def fake_localize(self, dt, is_dst=False): + raise NotImplementedError() + UTC.localize = new.instancemethod(fake_localize, UTC, UTC.__class__) + # This is important to trigger the actual bug (#257) + self.assertEqual(False, hasattr(UTC, 'normalize')) + return UTC + + def test_can_format_time_with_non_pytz_timezone(self): + # regression test for #257 + utc = self._utc() + t = datetime(2007, 4, 1, 15, 30, tzinfo=utc) + formatted_time = dates.format_time(t, 'long', tzinfo=utc, locale='en') + self.assertEqual('3:30:00 PM +0000', formatted_time) + + def suite(): suite = unittest.TestSuite() suite.addTest(doctest.DocTestSuite(dates)) suite.addTest(unittest.makeSuite(DateTimeFormatTestCase)) suite.addTest(unittest.makeSuite(FormatDateTestCase)) suite.addTest(unittest.makeSuite(FormatTimeTestCase)) + suite.addTest(unittest.makeSuite(TimeZoneAdjustTestCase)) return suite if __name__ == '__main__':