Fixed #1385 -- Allowed timesince filter to accept datetime.date objects. Thanks, Matt

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2375 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2006-02-23 20:27:03 +00:00
parent a5fad0eb37
commit 9a74e89ef0
2 changed files with 8 additions and 1 deletions

View File

@ -15,6 +15,9 @@ def timesince(d, now=None):
(60 * 60, lambda n: ngettext('hour', 'hours', n)), (60 * 60, lambda n: ngettext('hour', 'hours', n)),
(60, lambda n: ngettext('minute', 'minutes', n)) (60, lambda n: ngettext('minute', 'minutes', n))
) )
# Convert datetime.date to datetime.datetime for comparison
if d.__class__ is not datetime.datetime:
d = datetime.datetime(d.year, d.month, d.day)
if now: if now:
t = now.timetuple() t = now.timetuple()
else: else:

View File

@ -237,6 +237,10 @@ False
>>> timesince(datetime.datetime.now() - datetime.timedelta(1)) >>> timesince(datetime.datetime.now() - datetime.timedelta(1))
'1 day' '1 day'
# datetime.date compataibility with timesince
>>> timesince(datetime.date.today() - datetime.timedelta(1))
'1 day, 23 hours'
>>> default("val", "default") >>> default("val", "default")
'val' 'val'