1. volpino
  2. django-timedelta-field

Commits

Matthew Schinckel  committed 03c6915

Added more tests

  • Participants
  • Parent commits 1913215
  • Branches default

Comments (0)

Files changed (2)

File timedelta/helpers.py

View file
  • Ignore whitespace
     else:
         return result
 
+def decimal_hours(timedelta):
+    """
+    Return a decimal value of the number of hours that this timedelta
+    object refers to.
+    """
+    return Decimal(timedelta.days*24) + Decimal(timedelta.seconds) / 3600

File timedelta/tests.py

View file
  • Ignore whitespace
         
         TODO: test with tzinfo (non-naive) datetimes/times.
         """
-    
+    
+    def test_decimal_hours(self):
+        """
+        >>> decimal_hours(datetime.timedelta(hours=5, minutes=30))
+        Decimal('5.5')
+        >>> decimal_hours(datetime.timedelta(hours=5))
+        Decimal('5')
+        >>> decimal_hours(datetime.timedelta(hours=9, minutes=20))
+        Decimal('9.333333333333333333333333333')
+        """