Files
_Geulbeot/02. Prompts/문서생성/codedomain/날짜_형식을_Python_v01.py

11 lines
411 B
Python

def format_date(date_str: str, source: str) -> str:
"""날짜 형식을 YYYY-MM-DD 로 변환"""
try:
match = re.search(r'\d{4}-\d{2}-\d{2}', date_str)
if match:
return match.group(0)
if source == '연합뉴스':
return datetime.strptime(date_str, '%m-%d %H:%M').strftime('2024-%m-%d')
return date_str
except Exception:
return date_str