Created
February 14, 2012 20:20
-
-
Save signed0/1829916 to your computer and use it in GitHub Desktop.
Human readable date range
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
def daterange(v0, v1): | |
assert v0 <= v1 | |
if v0 == v1: | |
return v0.strftime('%b %d, %Y') | |
if v0.year == v1.year: | |
if v0.month == v1.month: | |
parts = (v0.strftime('%b %d'), | |
v1.strftime('%d'), | |
v0.year | |
) | |
return '%s-%s, %i' % parts | |
else: | |
parts = (v0.strftime('%b %d'), | |
v1.strftime('%b %d'), | |
v0.year | |
) | |
return '%s - %s, %i' % parts | |
else: | |
return '%s - %s' % (v0.strftime('%b %d, %Y'), v1.strftime('%b %d, %Y')) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment