fix when Interval is coming from date substraction stable
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Tue, 15 Sep 2009 16:31:45 +0200
branchstable
changeset 3235 bad0ff9b0c13
parent 3211 7918d4a5cdbf
child 3236 df31dbf3225e
fix when Interval is coming from date substraction
web/views/baseviews.py
--- a/web/views/baseviews.py	Mon Sep 14 16:24:01 2009 +0200
+++ b/web/views/baseviews.py	Tue Sep 15 16:31:45 2009 +0200
@@ -15,6 +15,8 @@
 __docformat__ = "restructuredtext en"
 _ = unicode
 
+from datetime import timedelta
+
 from rql import nodes
 
 from logilab.mtconverter import TransformError, xml_escape, xml_escape
@@ -77,6 +79,10 @@
                 self.w(entity.printable_value(rtype, value, format=format))
                 return
         if etype in ('Time', 'Interval'):
+            if etype == 'Interval' and isinstance(value, (int, long)):
+                # `date - date`, unlike `datetime - datetime` gives an int
+                # (number of days), not a timedelta
+                value = timedelta(days=value)
             # value is DateTimeDelta but we have no idea about what is the
             # reference date here, so we can only approximate years and months
             if format == 'text/html':