web/views/baseviews.py
branch3.5
changeset 3264 5d1f3f6c042d
parent 3165 0a50ebe53db7
parent 3236 df31dbf3225e
child 3293 69c0ba095536
child 3682 9b62c5887639
--- a/web/views/baseviews.py	Wed Sep 16 17:27:04 2009 +0200
+++ b/web/views/baseviews.py	Wed Sep 16 17:29: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,13 @@
                 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
+                # XXX should rql be fixed to return Int instead of Interval in
+                #     that case? that would be probably the proper fix but we
+                #     loose information on the way...
+                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':