Loading django/utils/timesince.py +5 −0 Original line number Diff line number Diff line from __future__ import unicode_literals import calendar import datetime from django.utils.html import avoid_wrapping Loading Loading @@ -40,6 +41,10 @@ def timesince(d, now=None, reversed=False): now = datetime.datetime.now(utc if is_aware(d) else None) delta = (d - now) if reversed else (now - d) # Deal with leapyears by subtracing the number of leapdays delta -= datetime.timedelta(calendar.leapdays(d.year, now.year)) # ignore microseconds since = delta.days * 24 * 60 * 60 + delta.seconds if since <= 0: Loading docs/releases/1.9.txt +3 −0 Original line number Diff line number Diff line Loading @@ -297,6 +297,9 @@ Templates the ability to register libraries and builtins explicitly through the template :setting:`OPTIONS <TEMPLATES-OPTIONS>`. * The ``timesince`` and ``timeuntil`` filters were improved to deal with leap years when given large time spans. Requests and Responses ^^^^^^^^^^^^^^^^^^^^^^ Loading tests/utils_tests/test_timesince.py +4 −0 Original line number Diff line number Diff line Loading @@ -131,3 +131,7 @@ class TimesinceTests(unittest.TestCase): self.assertEqual(timesince(future), '0\xa0minutes') past = datetime.datetime(1980, 1, 1, tzinfo=naive()) self.assertEqual(timeuntil(past), '0\xa0minutes') def test_thousand_years_ago(self): t = datetime.datetime(1007, 8, 14, 13, 46, 0) self.assertEqual(timesince(t, self.t), '1000\xa0years') Loading
django/utils/timesince.py +5 −0 Original line number Diff line number Diff line from __future__ import unicode_literals import calendar import datetime from django.utils.html import avoid_wrapping Loading Loading @@ -40,6 +41,10 @@ def timesince(d, now=None, reversed=False): now = datetime.datetime.now(utc if is_aware(d) else None) delta = (d - now) if reversed else (now - d) # Deal with leapyears by subtracing the number of leapdays delta -= datetime.timedelta(calendar.leapdays(d.year, now.year)) # ignore microseconds since = delta.days * 24 * 60 * 60 + delta.seconds if since <= 0: Loading
docs/releases/1.9.txt +3 −0 Original line number Diff line number Diff line Loading @@ -297,6 +297,9 @@ Templates the ability to register libraries and builtins explicitly through the template :setting:`OPTIONS <TEMPLATES-OPTIONS>`. * The ``timesince`` and ``timeuntil`` filters were improved to deal with leap years when given large time spans. Requests and Responses ^^^^^^^^^^^^^^^^^^^^^^ Loading
tests/utils_tests/test_timesince.py +4 −0 Original line number Diff line number Diff line Loading @@ -131,3 +131,7 @@ class TimesinceTests(unittest.TestCase): self.assertEqual(timesince(future), '0\xa0minutes') past = datetime.datetime(1980, 1, 1, tzinfo=naive()) self.assertEqual(timeuntil(past), '0\xa0minutes') def test_thousand_years_ago(self): t = datetime.datetime(1007, 8, 14, 13, 46, 0) self.assertEqual(timesince(t, self.t), '1000\xa0years')