Commits

Matthew Schinckel committed 3a052c8

Compatibility with python <= 2.6.x: total_seconds

  • Participants
  • Parent commits dd7a2a2

Comments (0)

Files changed (2)

File timedelta/__init__.py

 
 try:
     from fields import TimedeltaField
-    from helpers import divide, multiply, modulo, parse, nice_repr, percentage, decimal_percentage
+    from helpers import (
+        divide, multiply, modulo, 
+        parse, nice_repr, 
+        percentage, decimal_percentage,
+        total_seconds
+    )
 except ImportError:
     pass

File timedelta/helpers.py

         date -= datetime.timedelta(date.weekday())
     
     return date, date + datetime.timedelta(6)
+
+try:
+    datetime.timedelta().total_seconds
+    def total_seconds(timedelta):
+        return timedelta.total_seconds()
+except AttributeError:
+    def total_seconds(timedelta):
+        """
+        Python < 2.7 does not have datetime.timedelta.total_seconds
+        """
+        return timedelta.days * 86400 + timedelta.seconds
+