Created
February 4, 2010 23:11
-
-
Save andymckay/295253 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using dateutil (easy_install python-dateutil) allows you to | |
# filter dates to a particular timezone eg: | |
# {{ hour.object|astimezone:'US/Eastern'|date:'G'}} | |
from django import template | |
from django.conf import settings | |
from dateutil import zoneinfo | |
register = template.Library() | |
@register.filter(name='astimezone') | |
def astimezone(date, timezone): | |
date = date.replace(tzinfo=zoneinfo.gettz(settings.TIME_ZONE)) | |
return date.astimezone(zoneinfo.gettz(timezone)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment