23 lines
768 B
Python
23 lines
768 B
Python
from datetime import date, timedelta
|
|
|
|
|
|
def checkio(from_date: date, to_date: date) -> int:
|
|
"""
|
|
Count the days of rest
|
|
"""
|
|
plus_a_day = timedelta(days=1)
|
|
count = 0
|
|
while from_date != to_date:
|
|
if from_date.weekday() == 5 or from_date.weekday() == 6:
|
|
count += 1
|
|
from_date += plus_a_day
|
|
count += 1 if to_date.weekday() == 5 or to_date.weekday() == 6 else 0
|
|
return count
|
|
|
|
|
|
# These "asserts" using only for self-checking and not necessary for auto-testing
|
|
if __name__ == '__main__':
|
|
assert checkio(date(2013, 9, 18), date(2013, 9, 23)) == 2, "1st example"
|
|
assert checkio(date(2013, 1, 1), date(2013, 2, 1)) == 8, "2nd example"
|
|
assert checkio(date(2013, 2, 2), date(2013, 2, 3)) == 2, "3rd example"
|