Count Business Days in A Month using Python

from datetime import date, timedelta
import json

PUBLIC_HOLIDAYS = (1, 3, 7)
today = date.today()
one_day = timedelta(days=1)
first_of_month = today.replace(day=1)
holidays = [date(year=today.year, month=today.month, day=d) for d in PUBLIC_HOLIDAYS]
b_count = 0
c_count = 0
day = first_of_month
while day <= today:
    if day.weekday() not in (5, 6) and day not in holidays:
        b_count += 1
    c_count += 1
    day = day + one_day

print('business day count: ', b_count)
print('calendar day count: ', c_count)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章