fix: 저녁 시작을 17시보다 이르지 않게 — 겨울에 오후 3시가 저녁이던 것

This commit is contained in:
skkim committed 2026-11-26 16:09:41 +09:00
1 parent 639ca83553
commit 96e40d00c8
7 files changed
+53 -20

No files matched your search

+9 -2
View File
@@ -6,15 +6,22 @@ SLOTS = ("morning", "day", "evening", "night")
SLOT_LABEL = {"morning": "아침", "day": "낮", "evening": "저녁", "night": "밤"}
NIGHT_AFTER_SUNSET = timedelta(hours=1) # 해 지고 이만큼 지나면 밤
NIGHT_END_HOUR = 5
EVENING_EARLIEST_HOUR = 17 # 겨울엔 일몰 2시간 전이 15시대라, 사람들이 아직 낮으로 느끼는 오후 3시가 저녁이 되지 않게
def evening_start(sunset_at: datetime) -> datetime:
"""저녁이 시작하는 시각: 일몰 2시간 전, 단 17시보다 이르지 않게."""
sunset = sunset_at.astimezone(KST)
return max(sunset - timedelta(hours=2), sunset.replace(hour=EVENING_EARLIEST_HOUR, minute=0, second=0, microsecond=0))
def slot_of(now: datetime, sunset_at: datetime) -> str:
"""아침 05–11 · 낮 11–일몰 2시간 전 · 저녁 일몰 2시간 전–일몰 1시간 뒤 · 밤 일몰 1시간 뒤–05. 밤은 계절 따라 18시대~21시대에 온다."""
"""아침 05–11 · 낮 11–저녁 시작 · 저녁 일몰 2시간 전(17시보다 이르지 않게)–일몰 1시간 뒤 · 밤 일몰 1시간 뒤–05. 밤은 계절 따라 18시대~21시대에 온다."""
h = now.hour
if NIGHT_END_HOUR <= h < 11:
return "morning"
if h >= 11 and now < sunset_at + NIGHT_AFTER_SUNSET:
return "day" if now < sunset_at - timedelta(hours=2) else "evening"
return "day" if now < evening_start(sunset_at) else "evening"
return "night"