Matthew Schinckel  committed f94b182

Added new template filters for number of seconds.

  • Participants
  • Parent commits 5e5a3f2
  • Branches default

Comments (0)

Files changed (3)

+0.6.6: Add in a couple of new template filters: total_seconds, and total_seconds_sort.
+       The latter zero-pads the value to 10 places, ideal for lexical sorting.
+       This correctly sorts timedeltas of up to around 10 years, if you need more
+       you can pass an argument to the filter.
 0.6.5: Empty string values in database now are returned as None for the field value.
        Note that you must have field.null=True to store a NULL in the db.
        I'm still not 100% happy with this: postgres may choke on empty string values when doing INTERVAL comparisons.

File timedelta/templatetags/

 def decimal_hours(value, decimal_places=None):
-    return dh(value, decimal_places)
+    return dh(value, decimal_places)

File timedelta/templatetags/

 register = template.Library()
 # Don't really like using relative imports, but no choice here!
-from ..helpers import nice_repr, iso8601_repr
+from ..helpers import nice_repr, iso8601_repr, total_seconds as _total_seconds
 def timedelta(value, display="long"):
 def iso8601(value):
     return iso8601_repr(value)
+def total_seconds(value):
+    return _total_seconds(value)
+def total_seconds(value, places=10):
+    return ("%0" + str(places) + "i") % _total_seconds(value)