diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index 631118f4b9..1d0c6c6d22 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -7,7 +7,6 @@ from decimal import ROUND_HALF_UP, Context, Decimal, InvalidOperation from functools import wraps from pprint import pformat -from django.conf import settings from django.utils import formats, six from django.utils.dateformat import format, time_format from django.utils.encoding import force_text, iri_to_uri @@ -727,8 +726,6 @@ def date(value, arg=None): """Formats a date according to the given format.""" if value in (None, ''): return '' - if arg is None: - arg = settings.DATE_FORMAT try: return formats.date_format(value, arg) except AttributeError: @@ -743,8 +740,6 @@ def time(value, arg=None): """Formats a time according to the given format.""" if value in (None, ''): return '' - if arg is None: - arg = settings.TIME_FORMAT try: return formats.time_format(value, arg) except AttributeError: diff --git a/tests/template_tests/filter_tests/test_date.py b/tests/template_tests/filter_tests/test_date.py index 1740df47da..4c83068eb8 100644 --- a/tests/template_tests/filter_tests/test_date.py +++ b/tests/template_tests/filter_tests/test_date.py @@ -1,8 +1,8 @@ from datetime import datetime, time from django.template.defaultfilters import date -from django.test import SimpleTestCase -from django.utils import timezone +from django.test import SimpleTestCase, override_settings +from django.utils import timezone, translation from ..utils import setup from .timezone_utils import TimezoneTestCase @@ -20,6 +20,17 @@ class DateTests(TimezoneTestCase): output = self.engine.render_to_string('date02', {'d': datetime(2008, 1, 1)}) self.assertEqual(output, 'Jan. 1, 2008') + @override_settings(USE_L10N=True) + @setup({'date02_l10n': '{{ d|date }}'}) + def test_date02_l10n(self): + """ + Without arg and when USE_L10N is True, the active language's DATE_FORMAT + is used. + """ + with translation.override('fr'): + output = self.engine.render_to_string('date02_l10n', {'d': datetime(2008, 1, 1)}) + self.assertEqual(output, '1 janvier 2008') + @setup({'date03': '{{ d|date:"m" }}'}) def test_date03(self): """ diff --git a/tests/template_tests/filter_tests/test_time.py b/tests/template_tests/filter_tests/test_time.py index f5dc47813e..a05624a0e1 100644 --- a/tests/template_tests/filter_tests/test_time.py +++ b/tests/template_tests/filter_tests/test_time.py @@ -1,8 +1,8 @@ from datetime import time from django.template.defaultfilters import time as time_filter -from django.test import SimpleTestCase -from django.utils import timezone +from django.test import SimpleTestCase, override_settings +from django.utils import timezone, translation from ..utils import setup from .timezone_utils import TimezoneTestCase @@ -13,6 +13,18 @@ class TimeTests(TimezoneTestCase): #20693: Timezone support for the time template filter """ + @setup({'time00': '{{ dt|time }}'}) + def test_time00(self): + output = self.engine.render_to_string('time00', {'dt': time(16, 25)}) + self.assertEqual(output, '4:25 p.m.') + + @override_settings(USE_L10N=True) + @setup({'time00_l10n': '{{ dt|time }}'}) + def test_time00_l10n(self): + with translation.override('fr'): + output = self.engine.render_to_string('time00_l10n', {'dt': time(16, 25)}) + self.assertEqual(output, '16:25') + @setup({'time01': '{{ dt|time:"e:O:T:Z" }}'}) def test_time01(self): output = self.engine.render_to_string('time01', {'dt': self.now_tz_i})