43 lines
1.1 KiB
Python
43 lines
1.1 KiB
Python
"""
|
|
타임존 유틸리티
|
|
|
|
프로젝트 전역에서 일관된 서울 타임존(Asia/Seoul) 시간을 사용하기 위한 유틸리티입니다.
|
|
모든 datetime.now() 호출은 이 모듈의 함수로 대체해야 합니다.
|
|
"""
|
|
|
|
from datetime import datetime
|
|
|
|
from config import TIMEZONE
|
|
|
|
|
|
def now() -> datetime:
|
|
"""
|
|
서울 타임존(Asia/Seoul) 기준 현재 시간을 반환합니다.
|
|
|
|
Returns:
|
|
datetime: 서울 타임존이 적용된 현재 시간 (aware datetime)
|
|
|
|
Example:
|
|
>>> from app.utils.timezone import now
|
|
>>> current_time = now() # 2024-01-15 15:30:00+09:00
|
|
"""
|
|
return datetime.now(TIMEZONE)
|
|
|
|
|
|
def today_str(fmt: str = "%Y-%m-%d") -> str:
|
|
"""
|
|
서울 타임존 기준 오늘 날짜를 문자열로 반환합니다.
|
|
|
|
Args:
|
|
fmt: 날짜 포맷 (기본값: YYYY-MM-DD)
|
|
|
|
Returns:
|
|
str: 포맷된 날짜 문자열
|
|
|
|
Example:
|
|
>>> from app.utils.timezone import today_str
|
|
>>> today_str() # "2024-01-15"
|
|
>>> today_str("%Y/%m/%d") # "2024/01/15"
|
|
"""
|
|
return datetime.now(TIMEZONE).strftime(fmt)
|