From fce688cc743bd77c8e415c5a7a409b5fe211e6f7 Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Wed, 23 Nov 2005 21:13:00 +0000 Subject: [PATCH] Fixed #886 -- timesince utility now supports microseconds. Thanks, Aaron Swartz git-svn-id: http://code.djangoproject.com/svn/django/trunk@1374 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/utils/timesince.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/django/utils/timesince.py b/django/utils/timesince.py index b1df997e2e..89af456e96 100644 --- a/django/utils/timesince.py +++ b/django/utils/timesince.py @@ -1,4 +1,4 @@ -import datetime, time +import datetime, math, time from django.utils.tzinfo import LocalTimezone from django.utils.translation import ngettext @@ -30,6 +30,8 @@ def timesince(d, now=None): count = since / seconds if count != 0: break + if count < 0: + return '%d milliseconds' % math.floor(delta.microseconds / 1000) s = '%d %s' % (count, name(count)) if i + 1 < len(chunks): # Now get the second item