평일/휴일 구분 업데이트

This commit is contained in:
2025-07-28 13:14:59 +09:00
parent 3e9271517e
commit 2fdd2b38f7

View File

@ -4,7 +4,7 @@ sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))
import yaml
import requests
import xml.etree.ElementTree as ET
from datetime import datetime, date
from datetime import date, datetime, timedelta
from sqlalchemy import select, insert, delete
# config.yaml 경로 및 로딩
@ -134,8 +134,40 @@ def is_korean_holiday(dt: date) -> bool:
finally:
session.close()
def get_holiday_dates(start_date: date, end_date: date) -> set[date]:
"""특정 기간 내의 휴일 목록 반환"""
session = db.get_session()
try:
stmt = select(holiday_table.c.date).where(
holiday_table.c.date.between(start_date.strftime("%Y%m%d"), end_date.strftime("%Y%m%d"))
)
results = session.execute(stmt).scalars().all()
return set(datetime.strptime(d, "%Y%m%d").date() for d in results)
finally:
session.close()
def get_weekday_dates(start_date: date, end_date: date) -> set[date]:
"""특정 기간 중 평일(월~금 & 비휴일) 목록 반환"""
holiday_dates = get_holiday_dates(start_date, end_date)
result = set()
curr = start_date
while curr <= end_date:
if curr.weekday() < 5 and curr not in holiday_dates: # 월(0)~금(4)
result.add(curr)
curr += timedelta(days=1)
return result
if __name__ == "__main__":
print("📌 특일정보 초기화 시작")
print("📌 휴일 테스트 시작")
init_holidays()
print("✅ 특일정보 초기화 완료")
from datetime import date
start = date(2025, 1, 1)
end = date(2025, 12, 31)
holidays = get_holiday_dates(start, end)
print(f"🔍 {start} ~ {end} 사이 휴일 {len(holidays)}")
for d in sorted(holidays):
print(" -", d)