Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplified django.utils.formats.date_format()/time_format() calls. #16423

Merged
merged 1 commit into from
Jan 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion django/utils/formats.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
felixxm marked this conversation as resolved.
Show resolved Hide resolved
return value


Expand Down
25 changes: 6 additions & 19 deletions tests/i18n/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,26 +550,13 @@ def test_all_format_strings(self):
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):
Expand Down Expand Up @@ -961,7 +948,7 @@ def test_l10n_enabled(self):
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),
)

Expand Down