Created
August 18, 2014 05:58
-
-
Save ergoithz/1acca183279ffaef9ccf to your computer and use it in GitHub Desktop.
Self-healing date function
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
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