Timedelta template tag

 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

  1. Fuzzy Date Diff Template Filter by zain 2 years, 11 months ago
  2. Humanized and localized timesince template filter by slink 1 year, 2 months ago
  3. Smart i18n date diff (twitter like) by Batiste 2 years, 10 months ago
  4. UTC-based astimezone filter by miracle2k 3 months, 2 weeks ago
  5. Time toggle on mouseover template filter by soniiic 2 years, 9 months ago

Comments

(Forgotten your password?)