mirror of https://github.com/django/django.git
Simplified TimeFormat.g().
This commit is contained in:
parent
895f6e4992
commit
0cbccaebeb
|
@ -100,11 +100,7 @@ class TimeFormat(Formatter):
|
||||||
|
|
||||||
def g(self):
|
def g(self):
|
||||||
"Hour, 12-hour format without leading zeros; i.e. '1' to '12'"
|
"Hour, 12-hour format without leading zeros; i.e. '1' to '12'"
|
||||||
if self.data.hour == 0:
|
return self.data.hour % 12 or 12
|
||||||
return 12
|
|
||||||
if self.data.hour > 12:
|
|
||||||
return self.data.hour - 12
|
|
||||||
return self.data.hour
|
|
||||||
|
|
||||||
def G(self):
|
def G(self):
|
||||||
"Hour, 24-hour format without leading zeros; i.e. '0' to '23'"
|
"Hour, 24-hour format without leading zeros; i.e. '0' to '23'"
|
||||||
|
|
|
@ -178,3 +178,19 @@ class DateFormatTests(SimpleTestCase):
|
||||||
dateformat.format(datetime(year, 9, 8, 5, 0), 'y'),
|
dateformat.format(datetime(year, 9, 8, 5, 0), 'y'),
|
||||||
expected_date,
|
expected_date,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_twelve_hour_format(self):
|
||||||
|
tests = [
|
||||||
|
(0, '12'),
|
||||||
|
(1, '1'),
|
||||||
|
(11, '11'),
|
||||||
|
(12, '12'),
|
||||||
|
(13, '1'),
|
||||||
|
(23, '11'),
|
||||||
|
]
|
||||||
|
for hour, expected in tests:
|
||||||
|
with self.subTest(hour=hour):
|
||||||
|
self.assertEqual(
|
||||||
|
dateformat.format(datetime(2000, 1, 1, hour), 'g'),
|
||||||
|
expected,
|
||||||
|
)
|
||||||
|
|
Loading…
Reference in New Issue