mirror of
https://github.com/django/django.git
synced 2025-10-26 23:26:08 +00:00
Fixed #17937 -- Avoided an error in the timeuntil filter when it receives a date object. Thanks Dmitry Guyvoronsky for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@17774 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
@@ -3,7 +3,7 @@ import datetime
|
||||
from django.utils.timezone import is_aware, utc
|
||||
from django.utils.translation import ungettext, ugettext
|
||||
|
||||
def timesince(d, now=None):
|
||||
def timesince(d, now=None, reversed=False):
|
||||
"""
|
||||
Takes two datetime objects and returns the time between d and now
|
||||
as a nicely formatted string, e.g. "10 minutes". If d occurs after now,
|
||||
@@ -33,7 +33,7 @@ def timesince(d, now=None):
|
||||
if not now:
|
||||
now = datetime.datetime.now(utc if is_aware(d) else None)
|
||||
|
||||
delta = now - d
|
||||
delta = (d - now) if reversed else (now - d)
|
||||
# ignore microseconds
|
||||
since = delta.days * 24 * 60 * 60 + delta.seconds
|
||||
if since <= 0:
|
||||
@@ -57,6 +57,4 @@ def timeuntil(d, now=None):
|
||||
Like timesince, but returns a string measuring the time until
|
||||
the given time.
|
||||
"""
|
||||
if not now:
|
||||
now = datetime.datetime.now(utc if is_aware(d) else None)
|
||||
return timesince(now, d)
|
||||
return timesince(d, now, reversed=True)
|
||||
|
||||
Reference in New Issue
Block a user