Commits

Matthew Schinckel committed f9a87e8

Added helpers.decimal_percentage.

  • Participants
  • Parent commits 3a9dbc4

Comments (0)

Files changed (3)

File timedelta/__init__.py

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

File timedelta/helpers.py

     
     return divide(obj1 * 100, obj2, as_float=True)
 
+def decimal_percentage(obj1, obj2):
+    """
+    >>> decimal_percentage(datetime.timedelta(2), datetime.timedelta(4))
+    Decimal('50.0')
+    """
+    return Decimal(str(percentage(obj1, obj2)))
+    
+    
 def multiply(obj, val):
     """
     Allows for the multiplication of timedeltas by float values.

File timedelta/tests.py

         AssertionError: as_float=True is inappropriate when dividing timedelta by a number.
         """
     
-    def percentage(self):
+    def test_percentage(self):
         """
         >>> percentage(datetime.timedelta(4), datetime.timedelta(2))
         200.0
         
         """
     
+    def test_decimal_percentage(self):
+        """
+        >>> decimal_percentage(datetime.timedelta(4), datetime.timedelta(2))
+        Decimal('200.0')
+        >>> decimal_percentage(datetime.timedelta(2), datetime.timedelta(4))
+        Decimal('50.0')
+        
+        """
+    
+    
     def test_round_to_nearest(self):
         """
         >>> td = datetime.timedelta(minutes=30)