Created
April 10, 2013 19:45
-
-
Save blackrobot/5357816 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
from django import template | |
register = template.Library() | |
@register.simple_tag | |
def date_range(start, end): | |
""" Takes a start date, and end date, then formats them as a range. """ | |
if end - start >= 365: # More than a year | |
formats = ('%B %d, %Y', '%B %d, %Y') | |
elif end.month != start.month: # Same year, different months | |
formats = ('%B %d', '%B %d, %Y') | |
else: # Same month and year | |
formats = ('%B %d', '%d, %Y') | |
return start.strftime(formats[0]), '-', end.strftime(formats[1]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment