Commits

Matthew Schinckel committed f9a87e8

Added helpers.decimal_percentage.

Comments (0)

Files changed (3)

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

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.

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)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.