feat: delay show rotation during live recording window
Decouple the like-window boundary (Wed 10pm ET) from when the system rotates to a new show. NTR_SHOW_ROTATION_DELAY_HOURS=2 keeps the previous week's show visible during the ~2 hour recording, then creates the new show at midnight. Made-with: Cursor
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from datetime import datetime, timezone
|
||||
|
||||
from ntr_fetcher.week import get_show_week
|
||||
from ntr_fetcher.week import get_current_show_week, get_show_week
|
||||
|
||||
|
||||
def test_mid_week_thursday():
|
||||
@@ -36,3 +36,50 @@ def test_est_period_no_dst():
|
||||
start, end = get_show_week(now, show_day=2, show_hour=22)
|
||||
assert start == datetime(2026, 1, 15, 3, 0, 0, tzinfo=timezone.utc)
|
||||
assert end == datetime(2026, 1, 22, 3, 0, 0, tzinfo=timezone.utc)
|
||||
|
||||
|
||||
# --- get_current_show_week tests ---
|
||||
|
||||
|
||||
def test_current_show_week_zero_delay_matches_get_show_week():
|
||||
"""delay=0 is a passthrough to get_show_week."""
|
||||
now = datetime(2026, 1, 15, 12, 0, 0, tzinfo=timezone.utc)
|
||||
assert get_current_show_week(now, show_day=2, show_hour=22, rotation_delay_hours=0) == \
|
||||
get_show_week(now, show_day=2, show_hour=22)
|
||||
|
||||
|
||||
def test_current_show_week_in_gap_returns_old_week():
|
||||
"""Wed 22:30 EST (in the 2-hour gap) should still show the previous week."""
|
||||
# Wed Jan 14 22:30 EST = Thu Jan 15 03:30 UTC
|
||||
now = datetime(2026, 1, 15, 3, 30, 0, tzinfo=timezone.utc)
|
||||
start, end = get_current_show_week(now, show_day=2, show_hour=22, rotation_delay_hours=2)
|
||||
# Previous week: Wed Jan 7 22:00 EST = Jan 8 03:00 UTC
|
||||
assert start == datetime(2026, 1, 8, 3, 0, 0, tzinfo=timezone.utc)
|
||||
assert end == datetime(2026, 1, 15, 3, 0, 0, tzinfo=timezone.utc)
|
||||
|
||||
|
||||
def test_current_show_week_at_rotation_boundary():
|
||||
"""Thu 00:00 EST (exactly at midnight) should rotate to the new week."""
|
||||
# Thu Jan 15 00:00 EST = Thu Jan 15 05:00 UTC
|
||||
now = datetime(2026, 1, 15, 5, 0, 0, tzinfo=timezone.utc)
|
||||
start, end = get_current_show_week(now, show_day=2, show_hour=22, rotation_delay_hours=2)
|
||||
# New week: Wed Jan 14 22:00 EST = Jan 15 03:00 UTC
|
||||
assert start == datetime(2026, 1, 15, 3, 0, 0, tzinfo=timezone.utc)
|
||||
assert end == datetime(2026, 1, 22, 3, 0, 0, tzinfo=timezone.utc)
|
||||
|
||||
|
||||
def test_current_show_week_well_after_gap():
|
||||
"""Thursday afternoon is well past the gap — new week regardless of delay."""
|
||||
now = datetime(2026, 1, 15, 16, 0, 0, tzinfo=timezone.utc)
|
||||
start, end = get_current_show_week(now, show_day=2, show_hour=22, rotation_delay_hours=2)
|
||||
assert start == datetime(2026, 1, 15, 3, 0, 0, tzinfo=timezone.utc)
|
||||
assert end == datetime(2026, 1, 22, 3, 0, 0, tzinfo=timezone.utc)
|
||||
|
||||
|
||||
def test_current_show_week_before_show_time_unaffected():
|
||||
"""Wednesday before the show (e.g. 3pm ET) is unaffected by rotation delay."""
|
||||
# Wed Jan 14 15:00 EST = Wed Jan 14 20:00 UTC
|
||||
now = datetime(2026, 1, 14, 20, 0, 0, tzinfo=timezone.utc)
|
||||
with_delay = get_current_show_week(now, show_day=2, show_hour=22, rotation_delay_hours=2)
|
||||
without_delay = get_show_week(now, show_day=2, show_hour=22)
|
||||
assert with_delay == without_delay
|
||||
|
||||
Reference in New Issue
Block a user