timeto template filter

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
from django import template
from dateutil import tz
import datetime

register = template.Library()

@register.filter
def timeto(value):
    now = datetime.datetime.now(tz.tzutc())
    diff = value.astimezone(tz.tzutc()) - now
    minutes = diff.seconds / 60
    hours = minutes / 60
    mins = minutes - (hours * 60)
    return '%dhr %dmin' % (hours, mins)

More like this

  1. isoutc template filter by japerk 4 years, 1 month ago
  2. FuzzyDateTimeField by japerk 4 years, 1 month ago
  3. UTC DateTime field by ludo 5 years, 8 months ago
  4. JSON encode ISO UTC datetime by japerk 4 years, 1 month ago
  5. Natural language date/time form fields by jdriscoll 5 years, 11 months ago

Comments

(Forgotten your password?)