Fixed #18951 -- Formatting of microseconds.

Thanks olofom at gmail com for the report.
This commit is contained in:
Aymeric Augustin 2012-09-22 12:02:21 +02:00
parent baa33cd8fa
commit 822cfce3df
3 changed files with 8 additions and 3 deletions

View File

@ -110,8 +110,8 @@ class TimeFormat(Formatter):
return '%02d' % self.data.second return '%02d' % self.data.second
def u(self): def u(self):
"Microseconds" "Microseconds; i.e. '000000' to '999999'"
return self.data.microsecond return '%06d' %self.data.microsecond
class DateFormat(TimeFormat): class DateFormat(TimeFormat):

View File

@ -1251,7 +1251,7 @@ S English ordinal suffix for day of the ``'st'``, ``'nd'``,
month, 2 characters. month, 2 characters.
t Number of days in the given month. ``28`` to ``31`` t Number of days in the given month. ``28`` to ``31``
T Time zone of this machine. ``'EST'``, ``'MDT'`` T Time zone of this machine. ``'EST'``, ``'MDT'``
u Microseconds. ``0`` to ``999999`` u Microseconds. ``000000`` to ``999999``
U Seconds since the Unix Epoch U Seconds since the Unix Epoch
(January 1 1970 00:00:00 UTC). (January 1 1970 00:00:00 UTC).
w Day of the week, digits without ``'0'`` (Sunday) to ``'6'`` (Saturday) w Day of the week, digits without ``'0'`` (Sunday) to ``'6'`` (Saturday)

View File

@ -72,6 +72,11 @@ class DateFormatTests(unittest.TestCase):
self.assertEqual(dateformat.format(my_birthday, 'a'), 'p.m.') self.assertEqual(dateformat.format(my_birthday, 'a'), 'p.m.')
def test_microsecond(self):
# Regression test for #18951
dt = datetime(2009, 5, 16, microsecond=123)
self.assertEqual(dateformat.format(dt, 'u'), '000123')
def test_date_formats(self): def test_date_formats(self):
my_birthday = datetime(1979, 7, 8, 22, 00) my_birthday = datetime(1979, 7, 8, 22, 00)
timestamp = datetime(2008, 5, 19, 11, 45, 23, 123456) timestamp = datetime(2008, 5, 19, 11, 45, 23, 123456)