题目:
As the input you’ll get the date of the first vacation day in the format ‘YYYY-MM-DD’ and the total number of vacation days. Your task is to find out which day will be the first working day after the vacation. If it’ll be Saturday or Sunday then it should be the next Monday.
In this mission you have to ignore national holidays and consider only Saturdays and Sundays.
Also don’t forget about February 29th in the leap year and the situation when the vacation starts at the end of December of the one year and ends at the beginning of the next year.
Input: The first day of the vacation and the number of days in it.
Output: The date of the first working day.
Example:
vacation(‘2018-07-01’, 14) == ‘2018-07-16’
vacation(‘2018-02-19’, 10) == ‘2018-03-01’
vacation(‘2000-02-28’, 5) == ‘2000-03-06’
vacation(‘1999-12-20’, 14) == ‘2000-01-03’
链接:
https://py.checkio.org/en/mission/the-first-working-day/
代码:
from datetime import date
from datetime import datetime
def vacation(d, days):
dd = datetime.strptime(d, '%Y-%m-%d')
rel = 0
while rel < days:
dd += date.resolution
rel += 1
while dd.isoweekday() >=6 :
dd += date.resolution
return str(dd.date())