eight-hourr/backend/services/holidays_util.py

24 lines
623 B
Python
Raw Normal View History

2026-07-17 06:55:36 +00:00
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