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 3 years, 2 months ago
- Humanized and localized timesince template filter by slink 1 year, 6 months ago
- Human format Date representation by sachingupta006 2 months ago
- Smart i18n date diff (twitter like) by Batiste 3 years, 1 month ago
- UTC-based astimezone filter by miracle2k 7 months ago
Comments