import datetime
# 根据第一次计算出来的休息日数,计算还需要的工作日数。(递归调用)
def get_next_date(self, start_date, weekend_days):
if not weekend_days:
return start_date
new_weekend_days = 0
next_date = datetime.datetime.strptime(start_date.strftime("%Y-%m-%d"), "%Y-%m-%d")
for day in range(1, weekend_days + 1):
next_date = datetime.datetime.strptime(start_date.strftime("%Y-%m-%d"), "%Y-%m-%d") + datetime.timedelta(days=day)
if next_date.weekday() in (5, 6):
new_weekend_days += 1
if new_weekend_days:
next_date = self.get_next_date(next_date, new_weekend_days)
return next_date
def workdays(self, receiv_date, testing_cycle=0, warning_days=0):
weekend_days = 0
days = testing_cycle - warning_days
if not days or not receiv_date:
return ""
next_date = datetime.datetime.strptime(receiv_date, "%Y-%m-%d")
# 首次计算包含周六、周日的天数
for day in range(1, days+1):
next_date = datetime.datetime.strptime(receiv_date, "%Y-%m-%d") + datetime.timedelta(days=day)
if next_date.weekday() in (5, 6):
weekend_days += 1
end_date = weekend_days and self.get_next_date(next_date, weekend_days) or next_date
return end_date.strftime("%Y-%m-%d")