如果我们有开始日期和间隔,则查找结束日期。不包括自定义假期列表和周末。在 Python(Django)
Find End Date If We Have Start Date and Interval . Excluding custom holiday list and weekends . In Python(Django)
所以,我想要实现的是。
start_date = "2020-07-16"
number_of_days = 15
holidays = ["2020-07-19",2020-07-21]
现在我想计算结束日期,即 8 月 16 日 + 15 天,不包括我在列表中给出的所有自定义假期和所有周末(周日+周六)。
关于如何实现它的任何建议。到目前为止,我找到的解决方案是 使用 NumPy,但它不符合我的要求。
total_days = number_of_days
for i in number_of_days:
current_day = start_data + timedelta(days=i)
if current_day in holidays:
total_days += 1
elif current_day.isoweekday() in [6, 7]:
total_days += 1
end_date = start_date + timedelta(days= total_days)
我希望这至少可以接近你想要的答案,我不确定我目前在 phone.
上的确切语法
但是看看 NumPy 的答案,它到底有什么不符合你的要求的?
所以,我想要实现的是。
start_date = "2020-07-16"
number_of_days = 15
holidays = ["2020-07-19",2020-07-21]
现在我想计算结束日期,即 8 月 16 日 + 15 天,不包括我在列表中给出的所有自定义假期和所有周末(周日+周六)。
关于如何实现它的任何建议。到目前为止,我找到的解决方案是
total_days = number_of_days
for i in number_of_days:
current_day = start_data + timedelta(days=i)
if current_day in holidays:
total_days += 1
elif current_day.isoweekday() in [6, 7]:
total_days += 1
end_date = start_date + timedelta(days= total_days)
我希望这至少可以接近你想要的答案,我不确定我目前在 phone.
上的确切语法但是看看 NumPy 的答案,它到底有什么不符合你的要求的?