24 lines
623 B
Python
24 lines
623 B
Python
from __future__ import annotations
|
|
|
|
from datetime import date, timedelta
|
|
|
|
import holidays
|
|
|
|
|
|
def is_workday(d: date, country: str = "TW") -> bool:
|
|
if d.weekday() >= 5:
|
|
return False
|
|
tw_holidays = holidays.country_holidays(country, years={d.year})
|
|
return d not in tw_holidays
|
|
|
|
|
|
def iter_workdays(start: date, end: date, country: str = "TW") -> list[date]:
|
|
if start > end:
|
|
start, end = end, start
|
|
days: list[date] = []
|
|
current = start
|
|
while current <= end:
|
|
if is_workday(current, country):
|
|
days.append(current)
|
|
current += timedelta(days=1)
|
|
return days |