summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2012-09-22 12:02:21 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2012-09-22 12:02:21 +0200
commit822cfce3df53301d9f9f4c14bd8a0cb2a1956e2e (patch)
treea7f0a380b52fe66e99afbd48ce59ff50a76e426e
parentbaa33cd8faa16737524b1ac355802a10dd63571c (diff)
Fixed #18951 -- Formatting of microseconds.
Thanks olofom at gmail com for the report.
-rw-r--r--django/utils/dateformat.py4
-rw-r--r--docs/ref/templates/builtins.txt2
-rw-r--r--tests/regressiontests/utils/dateformat.py5
3 files changed, 8 insertions, 3 deletions
diff --git a/django/utils/dateformat.py b/django/utils/dateformat.py
index 6a91a370e5..b2586ba1ff 100644
--- a/django/utils/dateformat.py
+++ b/django/utils/dateformat.py
@@ -110,8 +110,8 @@ class TimeFormat(Formatter):
return '%02d' % self.data.second
def u(self):
- "Microseconds"
- return self.data.microsecond
+ "Microseconds; i.e. '000000' to '999999'"
+ return '%06d' %self.data.microsecond
class DateFormat(TimeFormat):
diff --git a/docs/ref/templates/builtins.txt b/docs/ref/templates/builtins.txt
index 514953d666..07ac284905 100644
--- a/docs/ref/templates/builtins.txt
+++ b/docs/ref/templates/builtins.txt
@@ -1251,7 +1251,7 @@ S English ordinal suffix for day of the ``'st'``, ``'nd'``,
month, 2 characters.
t Number of days in the given month. ``28`` to ``31``
T Time zone of this machine. ``'EST'``, ``'MDT'``
-u Microseconds. ``0`` to ``999999``
+u Microseconds. ``000000`` to ``999999``
U Seconds since the Unix Epoch
(January 1 1970 00:00:00 UTC).
w Day of the week, digits without ``'0'`` (Sunday) to ``'6'`` (Saturday)
diff --git a/tests/regressiontests/utils/dateformat.py b/tests/regressiontests/utils/dateformat.py
index 0f18bb2a4d..0f4fd67f6f 100644
--- a/tests/regressiontests/utils/dateformat.py
+++ b/tests/regressiontests/utils/dateformat.py
@@ -72,6 +72,11 @@ class DateFormatTests(unittest.TestCase):
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):
my_birthday = datetime(1979, 7, 8, 22, 00)
timestamp = datetime(2008, 5, 19, 11, 45, 23, 123456)