Author: gwilson
Date: 2009-03-30 16:32:34 -0500 (Mon, 30 Mar 2009)
New Revision: 10215

Modified:
   django/trunk/django/utils/timesince.py
   django/trunk/tests/regressiontests/templates/filters.py
Log:
Fixed #9065 -- Fixed the `timesince` and `timeuntil` template tags to work when 
both values involved are date objects, thanks to morty and mboersma for the 
patch.


Modified: django/trunk/django/utils/timesince.py
===================================================================
--- django/trunk/django/utils/timesince.py      2009-03-30 21:01:08 UTC (rev 
10214)
+++ django/trunk/django/utils/timesince.py      2009-03-30 21:32:34 UTC (rev 
10215)
@@ -25,9 +25,11 @@
       (60 * 60, lambda n: ungettext('hour', 'hours', n)),
       (60, lambda n: ungettext('minute', 'minutes', n))
     )
-    # Convert datetime.date to datetime.datetime for comparison
-    if d.__class__ is not datetime.datetime:
+    # Convert datetime.date to datetime.datetime for comparison.
+    if not isinstance(d, datetime.datetime):
         d = datetime.datetime(d.year, d.month, d.day)
+    if now and not isinstance(now, datetime.datetime):
+        now = datetime.datetime(now.year, now.month, now.day)
 
     if not now:
         if d.tzinfo:

Modified: django/trunk/tests/regressiontests/templates/filters.py
===================================================================
--- django/trunk/tests/regressiontests/templates/filters.py     2009-03-30 
21:01:08 UTC (rev 10214)
+++ django/trunk/tests/regressiontests/templates/filters.py     2009-03-30 
21:32:34 UTC (rev 10215)
@@ -7,7 +7,7 @@
 consistent.
 """
 
-from datetime import datetime, timedelta
+from datetime import date, datetime, timedelta
 
 from django.utils.tzinfo import LocalTimezone, FixedOffset
 from django.utils.safestring import mark_safe
@@ -28,6 +28,8 @@
     now = datetime.now()
     now_tz = datetime.now(LocalTimezone(now))
     now_tz_i = datetime.now(FixedOffset((3 * 60) + 15)) # imaginary time zone
+    today = date.today()
+
     return {
         # Default compare with datetime.now()
         'filter-timesince01' : ('{{ a|timesince }}', {'a': datetime.now() + 
timedelta(minutes=-1, seconds = -10)}, '1 minute'),
@@ -55,6 +57,10 @@
         'filter-timesince15' : ('{{ a|timesince:b }}', {'a': now, 'b': 
now_tz_i}, ''),
         'filter-timesince16' : ('{{ a|timesince:b }}', {'a': now_tz_i, 'b': 
now}, ''),
 
+        # Regression for #9065 (two date objects).
+        'filter-timesince17' : ('{{ a|timesince:b }}', {'a': today, 'b': 
today}, '0 minutes'),
+        'filter-timesince18' : ('{{ a|timesince:b }}', {'a': today, 'b': today 
+ timedelta(hours=24)}, '1 day'),
+
         # Default compare with datetime.now()
         'filter-timeuntil01' : ('{{ a|timeuntil }}', {'a':datetime.now() + 
timedelta(minutes=2, seconds = 10)}, '2 minutes'),
         'filter-timeuntil02' : ('{{ a|timeuntil }}', {'a':(datetime.now() + 
timedelta(days=1, seconds = 10))}, '1 day'),
@@ -74,6 +80,10 @@
         'filter-timeuntil10' : ('{{ a|timeuntil }}', {'a': now_tz_i}, '0 
minutes'),
         'filter-timeuntil11' : ('{{ a|timeuntil:b }}', {'a': now_tz_i, 'b': 
now_tz}, '0 minutes'),
 
+        # Regression for #9065 (two date objects).
+        'filter-timeuntil12' : ('{{ a|timeuntil:b }}', {'a': today, 'b': 
today}, '0 minutes'),
+        'filter-timeuntil13' : ('{{ a|timeuntil:b }}', {'a': today, 'b': today 
- timedelta(hours=24)}, '1 day'),
+
         'filter-addslash01': ("{% autoescape off %}{{ a|addslashes }} {{ 
b|addslashes }}{% endautoescape %}", {"a": "<a>'", "b": mark_safe("<a>'")}, 
ur"<a>\' <a>\'"),
         'filter-addslash02': ("{{ a|addslashes }} {{ b|addslashes }}", {"a": 
"<a>'", "b": mark_safe("<a>'")}, ur"&lt;a&gt;\&#39; <a>\'"),
 


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to