From de487af1ff7f2bacd83b70d50b649d8408ef886b Mon Sep 17 00:00:00 2001 From: KWON Date: Wed, 9 Jul 2025 17:35:46 +0900 Subject: [PATCH] =?UTF-8?q?=EC=9E=91=EB=85=84=EA=B3=BC=20=EB=8F=99?= =?UTF-8?q?=EC=9D=BC=ED=95=9C=20=EC=9A=94=EC=9D=BC=EC=9D=84=20=EB=B0=98?= =?UTF-8?q?=ED=99=98=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/weekly_visitor_forecast.py | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/lib/weekly_visitor_forecast.py b/lib/weekly_visitor_forecast.py index 1a3d3dd..0d40132 100644 --- a/lib/weekly_visitor_forecast.py +++ b/lib/weekly_visitor_forecast.py @@ -35,7 +35,34 @@ def get_this_week_dates(today=None): def get_last_year_same_weekdays(dates): - return [d.replace(year=d.year - 1) for d in dates] + """ + 작년의 동일한 요일을 가진 날짜를 반환 + (예: 2025-07-08(화) → 2024년 중 가장 가까운 화요일) + + Args: + dates (list of datetime.date): 기준 날짜 리스트 + + Returns: + list of datetime.date: 작년의 동일 요일 날짜 리스트 + """ + result = [] + for d in dates: + target_weekday = d.weekday() + last_year_date = d - timedelta(days=365) + + # 동일 요일 찾기: 주중 1주 범위 내에서 동일 요일 탐색 + delta = 0 + found = None + for offset in range(-3, 4): + candidate = last_year_date + timedelta(days=offset) + if candidate.weekday() == target_weekday: + found = candidate + break + if found: + result.append(found) + else: + result.append(last_year_date) # fallback + return result def pm25_grade(value):