Created
July 16, 2014 18:40
-
-
Save MaikKlein/a29a8565b8981b9f7fa7 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 nextDay(year, month, day): | |
"""Simple version: assume every month has 30 days""" | |
if day < 30: | |
return year, month, day + 1 | |
else: | |
if month == 12: | |
return year + 1, 1, 1 | |
else: | |
return year, month + 1, 1 | |
def daysBetweenDates(year1, month1, day1, year2, month2, day2): | |
days = 0 | |
nd = day1 | |
nm = month1 | |
ny = year1 | |
while not (nd == day2 and nm == month2 and ny == year2): | |
(ny, nm , nd) = nextDay(ny,nm,nd) | |
days += 1 | |
return days | |
def test(): | |
test_cases = [((2012,9,30,2012,10,30),30), | |
((2012,1,1,2013,1,1),360), | |
((2012,9,1,2012,9,4),3)] | |
for (args, answer) in test_cases: | |
result = daysBetweenDates(*args) | |
if result != answer: | |
print result | |
print "Test with data:", args, "failed" | |
else: | |
print result | |
print "Test case passed!" | |
test() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment