Skip to content

Instantly share code, notes, and snippets.

@ergoithz
Created August 18, 2014 05:58
Show Gist options
  • Save ergoithz/1acca183279ffaef9ccf to your computer and use it in GitHub Desktop.
Save ergoithz/1acca183279ffaef9ccf to your computer and use it in GitHub Desktop.
Self-healing date function
import calendar
def a(year, month, day):
year += (month-1) // 12
month = (month-1) % 12 + 1
while day > calendar.monthrange(year, month)[1]:
day -= calendar.monthrange(year, month)[1]
year += month // 12
month = month % 12 + 1
print year, month, day
a(2000,2,31)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment