from datetime import date, datetime, timezone, timedelta CST = timezone(timedelta(hours=8)) # China Standard Time def today_cst() -> date: """Get today's date in Asia/Shanghai timezone.""" return datetime.now(timezone.utc).astimezone(CST).date() def parse_date(s: str) -> date: """Parse a date string that may be YYYY-MM-DD or a full ISO datetime.""" return date.fromisoformat(s[:10]) def is_working_day(d: date | None = None, holidays: set[date] | None = None, workdays: set[date] | None = None) -> bool: """Check if a date is a Chinese working day. Returns False for: - Saturdays and Sundays (weekday >= 5), UNLESS in the workdays set (调休) - Dates in the holidays set (weekday holidays like 春节/国庆) Returns True for: - Monday-Friday, unless in holidays set - Saturday/Sunday that are in the workdays set (调休 makeup days) """ d = d or today_cst() is_weekend = d.weekday() >= 5 # 调休: weekend that becomes a workday if is_weekend and workdays and d in workdays: return True # Normal weekend if is_weekend: return False # Weekday holiday if holidays and d in holidays: return False return True