mirror of https://github.com/django/django.git
Fixed #32735 -- Made DateFormat.Y() return a zero-padded year.
This commit is contained in:
parent
b1a4b1f0bd
commit
34363a391b
|
@ -313,8 +313,8 @@ class DateFormat(TimeFormat):
|
||||||
return '%02d' % (self.data.year % 100)
|
return '%02d' % (self.data.year % 100)
|
||||||
|
|
||||||
def Y(self):
|
def Y(self):
|
||||||
"Year, 4 digits; e.g. '1999'"
|
"""Year, 4 digits with leading zeros; e.g. '1999'."""
|
||||||
return self.data.year
|
return '%04d' % self.data.year
|
||||||
|
|
||||||
def z(self):
|
def z(self):
|
||||||
"""Day of the year, i.e. 1 to 366."""
|
"""Day of the year, i.e. 1 to 366."""
|
||||||
|
|
|
@ -1367,7 +1367,7 @@ Format character Description Example output
|
||||||
``t`` Number of days in the given month. ``28`` to ``31``
|
``t`` Number of days in the given month. ``28`` to ``31``
|
||||||
**Year**
|
**Year**
|
||||||
``y`` Year, 2 digits with leading zeros. ``'00'`` to ``'99'``
|
``y`` Year, 2 digits with leading zeros. ``'00'`` to ``'99'``
|
||||||
``Y`` Year, 4 digits. ``'1999'``
|
``Y`` Year, 4 digits with leading zeros. ``'0001'``, ..., ``'1999'``, ..., ``'9999'``
|
||||||
``L`` Boolean for whether it's a leap year. ``True`` or ``False``
|
``L`` Boolean for whether it's a leap year. ``True`` or ``False``
|
||||||
``o`` ISO-8601 week-numbering year, ``'1999'``
|
``o`` ISO-8601 week-numbering year, ``'1999'``
|
||||||
corresponding to the ISO-8601 week
|
corresponding to the ISO-8601 week
|
||||||
|
|
|
@ -166,7 +166,7 @@ class DateFormatTests(SimpleTestCase):
|
||||||
'Sun, 08 Jul 1979 22:00:00 +0100',
|
'Sun, 08 Jul 1979 22:00:00 +0100',
|
||||||
)
|
)
|
||||||
|
|
||||||
def test_year_before_1000(self):
|
def test_y_format_year_before_1000(self):
|
||||||
tests = [
|
tests = [
|
||||||
(476, '76'),
|
(476, '76'),
|
||||||
(42, '42'),
|
(42, '42'),
|
||||||
|
@ -179,6 +179,10 @@ class DateFormatTests(SimpleTestCase):
|
||||||
expected_date,
|
expected_date,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_Y_format_year_before_1000(self):
|
||||||
|
self.assertEqual(dateformat.format(datetime(1, 1, 1), 'Y'), '0001')
|
||||||
|
self.assertEqual(dateformat.format(datetime(999, 1, 1), 'Y'), '0999')
|
||||||
|
|
||||||
def test_twelve_hour_format(self):
|
def test_twelve_hour_format(self):
|
||||||
tests = [
|
tests = [
|
||||||
(0, '12'),
|
(0, '12'),
|
||||||
|
|
Loading…
Reference in New Issue