That is: timedelta template filter for Django :)
Format timedelta values nicely in your templates.
v0.1.2
New template filter named "timedelta"
A timedelta value: 4:03:21
rendered using: {{ dt }}
A timedelta value with django-timedeltatemplatefilter filter:
04:03:21
, rendered using:
{{ dt|timedelta:"{hours2}:{minutes2}:{seconds2}" }}
04:03
, rendered using:
{{ dt|timedelta:"{hours2}:{minutes2}" }}
4:3
, rendered using:
{{ dt|timedelta:"{hours}:{minutes}" }}
Another timedelta value: 2620 days, 4:03:21
, rendered using: {{ dt2 }}
A timedelta value with django-timedeltatemplatefilter filter:
2620 days, 04:03:21
, rendered using:
{{ dt2|timedelta:"{days_total} days, {hours2}:{minutes2}:{seconds2}" }}
7 years, 65 days, 4 hours
, rendered using:
{{ dt2|timedelta:"{years} years, {days} days, {hours} hours" }}
62884 hours
, rendered using:
{{ dt2|timedelta:"{hours_total} hours" }}
pip install django_timedeltatemplatefilter
You are hereby granted the right to do a copy and paste :)
Or you could just take the timedeltatemplatefilter
directory and dump it next to your other apps, if you'd like.... for some reason... yeah.
Pretty much anywhere in your INSTALLED_APPS...
INSTALLED_APPS = (
# ... stuff ...
'timedeltatemplatefilter',
# ... stuff ---
)
In any template that you with to use this filter in, add:
{% load timedelta_filter %}
to the top, but after {% extends ... %}
.
See the example at the top of this file.
- seconds
- minutes
- hours
- days
- years
{seconds}
- number of seconds until full minute{seconds_total}
- total number of seconds{minutes}
- number of minutes until full hour{minutes_total}
- total number of minutes, rounded down{hours}
- number of hours until full day{hours_total}
- total number of hours, rounded down{days}
- number of days until full year*{days_total}
- total number of days, rounded down{years}
- number of years*{years_total}
- alias for {years}
* Leap years are not taken into account, 1 year = 365 days
A few values are available in 2-digit form. Means that one-digit values are going to be padded with a 0
in front. These are:
{seconds2}
{minutes2}
{hours2}
See python's string format function.
- add a template tag that provides a nice python object in template context, so that we can use it like
{{ dt.hours }}:{{ dt.minutes }}
etc.