summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Pope <nick@nickpope.me.uk>2022-10-12 13:23:04 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-01-04 11:47:14 +0100
commit0fdc5d79b6cfe7317fd6b19f4cdf2183f2d048d1 (patch)
treef9cc2996ae5a2693c0dbf4cc517b3093a881053e
parent5cf9ff970e08b10d3f7d62734dbce9e8eaeff453 (diff)
Simplified django.utils.formats.date_format()/time_format() calls.
This removes redundant get_format() calls and passing a default value for the format argument.
-rw-r--r--django/utils/formats.py2
-rw-r--r--tests/i18n/tests.py25
2 files changed, 7 insertions, 20 deletions
diff --git a/django/utils/formats.py b/django/utils/formats.py
index b0a66e4e25..85d24b9443 100644
--- a/django/utils/formats.py
+++ b/django/utils/formats.py
@@ -217,7 +217,7 @@ def localize(value, use_l10n=None):
elif isinstance(value, datetime.date):
return date_format(value, use_l10n=use_l10n)
elif isinstance(value, datetime.time):
- return time_format(value, "TIME_FORMAT", use_l10n=use_l10n)
+ return time_format(value, use_l10n=use_l10n)
return value
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
index 7d2300c1b5..0adacb765e 100644
--- a/tests/i18n/tests.py
+++ b/tests/i18n/tests.py
@@ -550,26 +550,13 @@ class FormattingTests(SimpleTestCase):
self.assertIn(
"23", time_format(some_datetime)
) # Uses TIME_FORMAT by default
+ self.assertIn("2017", date_format(some_datetime, "DATETIME_FORMAT"))
+ self.assertIn("2017", date_format(some_date, "YEAR_MONTH_FORMAT"))
+ self.assertIn("14", date_format(some_date, "MONTH_DAY_FORMAT"))
+ self.assertIn("2017", date_format(some_date, "SHORT_DATE_FORMAT"))
self.assertIn(
"2017",
- date_format(some_datetime, format=get_format("DATETIME_FORMAT")),
- )
- self.assertIn(
- "2017",
- date_format(some_date, format=get_format("YEAR_MONTH_FORMAT")),
- )
- self.assertIn(
- "14", date_format(some_date, format=get_format("MONTH_DAY_FORMAT"))
- )
- self.assertIn(
- "2017",
- date_format(some_date, format=get_format("SHORT_DATE_FORMAT")),
- )
- self.assertIn(
- "2017",
- date_format(
- some_datetime, format=get_format("SHORT_DATETIME_FORMAT")
- ),
+ date_format(some_datetime, "SHORT_DATETIME_FORMAT"),
)
def test_locale_independent(self):
@@ -961,7 +948,7 @@ class FormattingTests(SimpleTestCase):
Template('{{ dt|date:"SHORT_DATETIME_FORMAT" }}').render(self.ctxt),
)
self.assertEqual(
- date_format(datetime.datetime.now(), "DATE_FORMAT"),
+ date_format(datetime.datetime.now()),
Template('{% now "DATE_FORMAT" %}').render(self.ctxt),
)