Add n business days to a given date ignoring holidays and weekends in python

前端 未结 11 634
天涯浪人
天涯浪人 2020-12-05 10:32

I\'m trying to add n (integer) working days to a given date, the date addition has to avoid the holidays and weekends (it\'s not included in the working days)

11条回答
  •  眼角桃花
    2020-12-05 11:11

    similar to @omz solution but recursively:

    def add_days_skipping_weekends(start_date, days):
        if not days:
            return start_date
        start_date += timedelta(days=1)
        if start_date.weekday() < 5:
            days -= 1
        return add_days_skipping_weekends(start_date, days)
    

提交回复
热议问题