Matthew Schinckel  committed 23b681d

Allow for decimal_hours to have a varying number of decimal places

  • Participants
  • Parent commits 0b96dc4
  • Branches default

Comments (0)

Files changed (2)

File timedelta/

         return result
-def decimal_hours(timedelta):
+def decimal_hours(timedelta, decimal_places=None):
     Return a decimal value of the number of hours that this timedelta
     object refers to.
-    return Decimal(timedelta.days*24) + Decimal(timedelta.seconds) / 3600
+    hours = Decimal(timedelta.days*24) + Decimal(timedelta.seconds) / 3600
+    if decimal_places:
+        return hours.quantize(Decimal(str(10**-decimal_places)))
+    return hours
 def week_containing(date):
     if date.weekday():

File timedelta/templatetags/

 from ..helpers import decimal_hours as dh
-def decimal_hours(value):
-    return dh(value)
+def decimal_hours(value, decimal_places=None):
+    return dh(value, decimal_places)