작년과 동일한 요일을 반환할 수 있도록 수정
This commit is contained in:
@ -35,7 +35,34 @@ def get_this_week_dates(today=None):
|
|||||||
|
|
||||||
|
|
||||||
def get_last_year_same_weekdays(dates):
|
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):
|
def pm25_grade(value):
|
||||||
|
|||||||
Reference in New Issue
Block a user