Fixed #19370 -- Made date filter properly handle midnight value
This commit is contained in:
parent
d37483c533
commit
c10aaa70a4
|
@ -704,7 +704,7 @@ def get_digit(value, arg):
|
||||||
@register.filter(expects_localtime=True, is_safe=False)
|
@register.filter(expects_localtime=True, is_safe=False)
|
||||||
def date(value, arg=None):
|
def date(value, arg=None):
|
||||||
"""Formats a date according to the given format."""
|
"""Formats a date according to the given format."""
|
||||||
if not value:
|
if value in (None, ''):
|
||||||
return ''
|
return ''
|
||||||
if arg is None:
|
if arg is None:
|
||||||
arg = settings.DATE_FORMAT
|
arg = settings.DATE_FORMAT
|
||||||
|
|
|
@ -8,7 +8,7 @@ consistent.
|
||||||
"""
|
"""
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date, datetime, time, timedelta
|
||||||
|
|
||||||
from django.test.utils import str_prefix
|
from django.test.utils import str_prefix
|
||||||
from django.utils.tzinfo import LocalTimezone, FixedOffset
|
from django.utils.tzinfo import LocalTimezone, FixedOffset
|
||||||
|
@ -356,6 +356,9 @@ def get_filter_tests():
|
||||||
# Timezone name
|
# Timezone name
|
||||||
'date06': (r'{{ d|date:"e" }}', {'d': datetime(2009, 3, 12, tzinfo=FixedOffset(30))}, '+0030'),
|
'date06': (r'{{ d|date:"e" }}', {'d': datetime(2009, 3, 12, tzinfo=FixedOffset(30))}, '+0030'),
|
||||||
'date07': (r'{{ d|date:"e" }}', {'d': datetime(2009, 3, 12)}, ''),
|
'date07': (r'{{ d|date:"e" }}', {'d': datetime(2009, 3, 12)}, ''),
|
||||||
|
# Ticket 19370: Make sure |date doesn't blow up on a midnight time object
|
||||||
|
'date08': (r'{{ t|date:"H:i" }}', {'t': time(0, 1)}, '00:01'),
|
||||||
|
'date09': (r'{{ t|date:"H:i" }}', {'t': time(0, 0)}, '00:00'),
|
||||||
|
|
||||||
# Tests for #11687 and #16676
|
# Tests for #11687 and #16676
|
||||||
'add01': (r'{{ i|add:"5" }}', {'i': 2000}, '2005'),
|
'add01': (r'{{ i|add:"5" }}', {'i': 2000}, '2005'),
|
||||||
|
|
Loading…
Reference in New Issue