feat: add week boundary computation with DST handling

Made-with: Cursor
This commit is contained in:
cottongin
2026-03-12 01:18:12 -04:00
parent 7e41f55e26
commit 38dda5dda0
2 changed files with 76 additions and 0 deletions

38
tests/test_week.py Normal file
View File

@@ -0,0 +1,38 @@
from datetime import datetime, timezone
from ntr_fetcher.week import get_show_week, SHOW_DAY_DEFAULT, SHOW_HOUR_DEFAULT
def test_mid_week_thursday():
"""Thursday should belong to the show that started the previous Wednesday."""
# 2025-03-13 is Thursday (2026-03-13 is Friday)
now = datetime(2025, 3, 13, 15, 0, 0, tzinfo=timezone.utc)
start, end = get_show_week(now, show_day=2, show_hour=22)
assert start == datetime(2025, 3, 13, 2, 0, 0, tzinfo=timezone.utc)
assert end == datetime(2025, 3, 20, 2, 0, 0, tzinfo=timezone.utc)
def test_wednesday_before_show():
"""Wednesday before 22:00 ET belongs to the previous week's show."""
# 2025-03-12 is Wednesday
now = datetime(2025, 3, 12, 20, 0, 0, tzinfo=timezone.utc)
start, end = get_show_week(now, show_day=2, show_hour=22)
assert start == datetime(2025, 3, 6, 3, 0, 0, tzinfo=timezone.utc)
assert end == datetime(2025, 3, 13, 2, 0, 0, tzinfo=timezone.utc)
def test_wednesday_after_show_starts():
"""Wednesday at or after 22:00 ET belongs to the new week."""
# 2025-03-13 02:30 UTC = Wed 2025-03-12 22:30 ET
now = datetime(2025, 3, 13, 2, 30, 0, tzinfo=timezone.utc)
start, end = get_show_week(now, show_day=2, show_hour=22)
assert start == datetime(2025, 3, 13, 2, 0, 0, tzinfo=timezone.utc)
assert end == datetime(2025, 3, 20, 2, 0, 0, tzinfo=timezone.utc)
def test_est_period_no_dst():
"""January — firmly in EST (UTC-5)."""
now = datetime(2026, 1, 15, 12, 0, 0, tzinfo=timezone.utc)
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)