Skip to content

Instantly share code, notes, and snippets.

@jrabbit
Created July 8, 2010 16:58
Show Gist options
  • Save jrabbit/468303 to your computer and use it in GitHub Desktop.
Save jrabbit/468303 to your computer and use it in GitHub Desktop.
import time
daynum=int(time.strftime('%j'))
year=int(time.strftime('%y'))
composite=(year*365)+daynum
# def ordinal(num):
# ldig = num % 10
# l2dig = ldig % 10
# if l2dig == 1:
# suffix = 'th'
# elif ldig == 1:
# suffix = 'st'
# elif ldig == 2:
# suffix = 'nd'
# elif ldig == 3:
# suffix = 'rd'
# else:
# suffix = 'th'
# return '%d%s' % (num, suffix)
# #thanks David Zaslavsky. http://tinyurl.com/38ev44s
def ordinal(n):
if 10 <= n % 100 < 20:
return str(n) + 'th'
else:
return str(n) + {1 : 'st', 2 : 'nd', 3 : 'rd'}.get(n % 10, "th")
print "It is the %s day since President Bush declared mission accomplished in Iraq, \
the %s day since he declared victory in the Afghanistan, \
and %s day of the Deepwater Horizon disaster in the Gulf."% (ordinal(composite - 1214), ordinal(composite - 1625), ordinal(composite - 3759))
#Composite dates - date of occurance for July 8th
#2625 Iraq
#2214 Afg
#80 Oil
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment