From 5509eb862668ebeadd52248e2af124dfce2cce72 Mon Sep 17 00:00:00 2001 From: Danilo Bargen Date: Tue, 27 Nov 2012 21:22:18 +0100 Subject: [PATCH] [1.5.x] Fixed #19370 -- Made date filter properly handle midnight value Backport of c10aaa70a from master. --- django/template/defaultfilters.py | 2 +- tests/regressiontests/templates/filters.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py index e15440f90e..dac4e5ddb4 100644 --- a/django/template/defaultfilters.py +++ b/django/template/defaultfilters.py @@ -704,7 +704,7 @@ def get_digit(value, arg): @register.filter(expects_localtime=True, is_safe=False) def date(value, arg=None): """Formats a date according to the given format.""" - if not value: + if value in (None, ''): return '' if arg is None: arg = settings.DATE_FORMAT diff --git a/tests/regressiontests/templates/filters.py b/tests/regressiontests/templates/filters.py index 8b4aebbf22..7ba1681fd5 100644 --- a/tests/regressiontests/templates/filters.py +++ b/tests/regressiontests/templates/filters.py @@ -8,7 +8,7 @@ consistent. """ 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.utils.tzinfo import LocalTimezone, FixedOffset @@ -356,6 +356,9 @@ def get_filter_tests(): # Timezone name 'date06': (r'{{ d|date:"e" }}', {'d': datetime(2009, 3, 12, tzinfo=FixedOffset(30))}, '+0030'), '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 'add01': (r'{{ i|add:"5" }}', {'i': 2000}, '2005'),