Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fixed #7443: Corrected a long standing mistake in the timesince/timeu…

…ntil filters when using a parameter for 'now'. Thanks to Andrew Shearer <ashearerw@shearersoftware.com> for the report.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@8481 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 46da8ac9e5415ef88527cfaf49da5e4212b7cdd1 1 parent a0e87b7
Russell Keith-Magee authored August 23, 2008
2  django/template/defaultfilters.py
@@ -643,7 +643,7 @@ def timesince(value, arg=None):
643 643
     if not value:
644 644
         return u''
645 645
     if arg:
646  
-        return timesince(arg, value)
  646
+        return timesince(value, arg)
647 647
     return timesince(value)
648 648
 timesince.is_safe = False
649 649
 
9  tests/regressiontests/defaultfilters/tests.py
@@ -373,6 +373,15 @@
373 373
 >>> timesince(datetime.datetime.now() - datetime.timedelta(1))
374 374
 u'1 day'
375 375
 
  376
+>>> timesince(datetime.datetime(2005, 12, 29), datetime.datetime(2005, 12, 30))
  377
+u'1 day'
  378
+
  379
+>>> timeuntil(datetime.datetime.now() + datetime.timedelta(1))
  380
+u'1 day'
  381
+
  382
+>>> timeuntil(datetime.datetime(2005, 12, 30), datetime.datetime(2005, 12, 29))
  383
+u'1 day'
  384
+
376 385
 >>> default(u"val", u"default")
377 386
 u'val'
378 387
 
19  tests/regressiontests/templates/filters.py
@@ -34,11 +34,17 @@ def get_filter_tests():
34 34
         'filter-timesince03' : ('{{ a|timesince }}', {'a': datetime.now() - timedelta(hours=1, minutes=25, seconds = 10)}, '1 hour, 25 minutes'),
35 35
 
36 36
         # Compare to a given parameter
37  
-        'filter-timesince04' : ('{{ a|timesince:b }}', {'a':now + timedelta(days=2), 'b':now + timedelta(days=1)}, '1 day'),
38  
-        'filter-timesince05' : ('{{ a|timesince:b }}', {'a':now + timedelta(days=2, minutes=1), 'b':now + timedelta(days=2)}, '1 minute'),
  37
+        'filter-timesince04' : ('{{ a|timesince:b }}', {'a':now - timedelta(days=2), 'b':now - timedelta(days=1)}, '1 day'),
  38
+        'filter-timesince05' : ('{{ a|timesince:b }}', {'a':now - timedelta(days=2, minutes=1), 'b':now - timedelta(days=2)}, '1 minute'),
39 39
 
40 40
         # Check that timezone is respected
41  
-        'filter-timesince06' : ('{{ a|timesince:b }}', {'a':now_tz + timedelta(hours=8), 'b':now_tz}, '8 hours'),
  41
+        'filter-timesince06' : ('{{ a|timesince:b }}', {'a':now_tz - timedelta(hours=8), 'b':now_tz}, '8 hours'),
  42
+
  43
+        # Regression for #7443
  44
+        'filter-timesince07': ('{{ earlier|timesince }}', { 'earlier': now - timedelta(days=7) }, '1 week'),
  45
+        'filter-timesince08': ('{{ earlier|timesince:now }}', { 'now': now, 'earlier': now - timedelta(days=7) }, '1 week'),
  46
+        'filter-timesince09': ('{{ later|timesince }}', { 'later': now + timedelta(days=7) }, '0 minutes'),
  47
+        'filter-timesince10': ('{{ later|timesince:now }}', { 'now': now, 'later': now + timedelta(days=7) }, '0 minutes'),
42 48
 
43 49
         # Default compare with datetime.now()
44 50
         'filter-timeuntil01' : ('{{ a|timeuntil }}', {'a':datetime.now() + timedelta(minutes=2, seconds = 10)}, '2 minutes'),
@@ -49,6 +55,13 @@ def get_filter_tests():
49 55
         'filter-timeuntil04' : ('{{ a|timeuntil:b }}', {'a':now - timedelta(days=1), 'b':now - timedelta(days=2)}, '1 day'),
50 56
         'filter-timeuntil05' : ('{{ a|timeuntil:b }}', {'a':now - timedelta(days=2), 'b':now - timedelta(days=2, minutes=1)}, '1 minute'),
51 57
 
  58
+        # Regression for #7443
  59
+        'filter-timeuntil06': ('{{ earlier|timeuntil }}', { 'earlier': now - timedelta(days=7) }, '0 minutes'),
  60
+        'filter-timeuntil07': ('{{ earlier|timeuntil:now }}', { 'now': now, 'earlier': now - timedelta(days=7) }, '0 minutes'),
  61
+        'filter-timeuntil08': ('{{ later|timeuntil }}', { 'later': now + timedelta(days=7) }, '1 week'),
  62
+        'filter-timeuntil09': ('{{ later|timeuntil:now }}', { 'now': now, 'earlier': now - timedelta(days=7) }, '1 week'),
  63
+
  64
+
52 65
         'filter-addslash01': ("{% autoescape off %}{{ a|addslashes }} {{ b|addslashes }}{% endautoescape %}", {"a": "<a>'", "b": mark_safe("<a>'")}, ur"<a>\' <a>\'"),
53 66
         'filter-addslash02': ("{{ a|addslashes }} {{ b|addslashes }}", {"a": "<a>'", "b": mark_safe("<a>'")}, ur"&lt;a&gt;\&#39; <a>\'"),
54 67
 

0 notes on commit 46da8ac

Please sign in to comment.
Something went wrong with that request. Please try again.