1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | from django import template
from django.utils.timesince import timesince
from datetime import datetime
register = template.Library()
def timedelta(value, arg=None):
if not value:
return ''
if arg:
cmp = arg
else:
cmp = datetime.now()
if value > cmp:
return "in %s" % timesince(cmp,value)
else:
return "%s ago" % timesince(value,cmp)
register.filter('timedelta',timedelta)
|
More like this
- Fuzzy Date Diff Template Filter by zain 4 years, 2 months ago
- humanize time difference (how long ago) by supsupmo 5 years, 8 months ago
- Humanized and localized timesince template filter by slink 2 years, 5 months ago
- Smart i18n date diff (twitter like) by Batiste 4 years, 1 month ago
- Frequently used tags/filters for Jinja2 by mathwizard 4 years, 8 months ago
Comments