summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAdrian Holovaty <adrian@holovaty.com>2006-02-23 20:27:03 +0000
committerAdrian Holovaty <adrian@holovaty.com>2006-02-23 20:27:03 +0000
commit9a74e89ef06433e53e6926a07d42c30d22840682 (patch)
tree2e369ca6d19512d345619a53a67daf37dbc48193 /django
parenta5fad0eb37fd78ce4cdc26dd6bf2510c5ccc5fc9 (diff)
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
Diffstat (limited to 'django')
-rw-r--r--django/utils/timesince.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/django/utils/timesince.py b/django/utils/timesince.py
index 0d1ab470e5..a16616584b 100644
--- a/django/utils/timesince.py
+++ b/django/utils/timesince.py
@@ -15,6 +15,9 @@ def timesince(d, now=None):
(60 * 60, lambda n: ngettext('hour', 'hours', 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:
t = now.timetuple()
else:
@@ -24,7 +27,7 @@ def timesince(d, now=None):
else:
tz = None
now = datetime.datetime(t[0], t[1], t[2], t[3], t[4], t[5], tzinfo=tz)
-
+
# ignore microsecond part of 'd' since we removed it from 'now'
delta = now - (d - datetime.timedelta(0, 0, d.microsecond))
since = delta.days * 24 * 60 * 60 + delta.seconds