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)