feat: 밤 시작을 21시 고정에서 일몰 1시간 뒤로 (계절 따라)
This commit is contained in:
1 parent
c00623e690
commit
498e4d677a
5 files changed
+18
-13
No files matched your search
@@ -74,6 +74,7 @@ _CATEGORY_META = {ArticleCategory.SEASON.value: "계절 소식", ArticleCategory
|
||||
_FEED_TTL_MAX = 3600
|
||||
_PARTIAL_TTL = 60
|
||||
_SUNSET_HOUR = 18 # 노을 시간대 각의 대략적인 순서용
|
||||
_NIGHT_AFTER_SUNSET = timedelta(hours=1) # 해 지고 이만큼 지나면 밤
|
||||
_RAIN_PROB = 40
|
||||
_UV_SHOW = 3 # 자외선 포스트: 오늘 가장 셀 때 '보통' 이상이면 띄운다
|
||||
_HERO_RAIN_PROB = 60 # 히어로 '오늘 비': 오늘 남은 칸 중 비 형태가 있거나 확률이 이만큼 넘는 첫 칸
|
||||
@@ -140,11 +141,11 @@ def feed_day(now: datetime) -> date:
|
||||
|
||||
|
||||
def slot_of(now: datetime, sunset_at: datetime) -> str:
|
||||
"""아침 05–11 · 낮 11–일몰 2시간 전 · 저녁 일몰 2시간 전–21 · 밤 21–05."""
|
||||
"""아침 05–11 · 낮 11–일몰 2시간 전 · 저녁 일몰 2시간 전–일몰 1시간 뒤 · 밤 일몰 1시간 뒤–05. 밤은 계절 따라 18시대~21시대에 온다."""
|
||||
h = now.hour
|
||||
if 5 <= h < 11:
|
||||
return "morning"
|
||||
if 11 <= h < 21:
|
||||
if h >= 11 and now < sunset_at + _NIGHT_AFTER_SUNSET:
|
||||
return "day" if now < sunset_at - timedelta(hours=2) else "evening"
|
||||
return "night"
|
||||
|
||||
@@ -154,7 +155,7 @@ def feed_ttl_sec(now: datetime, sunset_at: datetime) -> int:
|
||||
day = now.date()
|
||||
at = lambda d, h: datetime.combine(d, time(h), tzinfo=KST) # noqa: E731
|
||||
sunset = sunset_at.astimezone(KST)
|
||||
changes = [at(day, _FEED_DAY_START), at(day, 5), at(day, 11), sunset - timedelta(hours=2), sunset, at(day, 21),
|
||||
changes = [at(day, _FEED_DAY_START), at(day, 5), at(day, 11), sunset - timedelta(hours=2), sunset, sunset + _NIGHT_AFTER_SUNSET,
|
||||
at(day + timedelta(days=1), _FEED_DAY_START), next_vilage_available(now)]
|
||||
air = now.replace(minute=20, second=0, microsecond=0)
|
||||
changes.append(air if air > now else air + timedelta(hours=1))
|
||||
|
||||
@@ -100,8 +100,11 @@ def test_slot_follows_sunset():
|
||||
|
||||
sunset = datetime(2026, 10, 2, 18, 10, tzinfo=KST)
|
||||
at = lambda h, m=0: datetime(2026, 10, 2, h, m, tzinfo=KST) # noqa: E731
|
||||
assert [slot_of(at(h, m), sunset) for h, m in ((4, 59), (5, 0), (11, 0), (16, 9), (16, 10), (20, 59), (21, 0))] == [
|
||||
"night", "morning", "day", "day", "evening", "evening", "night"]
|
||||
assert [slot_of(at(h, m), sunset) for h, m in ((4, 59), (5, 0), (11, 0), (16, 9), (16, 10), (19, 9), (19, 10), (23, 0))] == [
|
||||
"night", "morning", "day", "day", "evening", "evening", "night", "night"]
|
||||
summer = datetime(2026, 6, 21, 19, 57, tzinfo=KST)
|
||||
assert slot_of(datetime(2026, 6, 21, 20, 30, tzinfo=KST), summer) == "evening"
|
||||
assert slot_of(datetime(2026, 6, 21, 20, 57, tzinfo=KST), summer) == "night"
|
||||
|
||||
|
||||
def test_arrange_orders_by_slot_and_keeps_same_types_apart():
|
||||
|
||||
Reference in new issue
Block a user