feat: add human-readable datetime formatting and !lastshow command
IRC plugins now format datetimes as "Wed Mar 11, 10:00 PM EDT" instead of raw ISO 8601. Configurable timezone defaults to America/New_York. Adds !lastshow N command to both Limnoria and Sopel plugins, returning track N from the previous week's show via existing API endpoints. Made-with: Cursor
This commit is contained in:
57
tests/test_format_dt.py
Normal file
57
tests/test_format_dt.py
Normal file
@@ -0,0 +1,57 @@
|
||||
"""Tests for the format_dt helper used by both IRC plugins.
|
||||
|
||||
The function is duplicated in both plugins (Limnoria and Sopel) since they
|
||||
can't share imports. This tests the logic independently of either IRC framework.
|
||||
"""
|
||||
from datetime import datetime
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
|
||||
def format_dt(iso_string: str | None, tz_name: str = "America/New_York") -> str:
|
||||
if not iso_string:
|
||||
return "never"
|
||||
dt = datetime.fromisoformat(iso_string)
|
||||
local = dt.astimezone(ZoneInfo(tz_name))
|
||||
return local.strftime("%a %b %-d, %-I:%M %p %Z")
|
||||
|
||||
|
||||
def test_format_dt_est():
|
||||
result = format_dt("2026-01-15T03:00:00+00:00")
|
||||
assert result == "Wed Jan 14, 10:00 PM EST"
|
||||
|
||||
|
||||
def test_format_dt_edt():
|
||||
result = format_dt("2026-03-12T02:00:00+00:00")
|
||||
assert result == "Wed Mar 11, 10:00 PM EDT"
|
||||
|
||||
|
||||
def test_format_dt_none():
|
||||
assert format_dt(None) == "never"
|
||||
|
||||
|
||||
def test_format_dt_empty_string():
|
||||
assert format_dt("") == "never"
|
||||
|
||||
|
||||
def test_format_dt_custom_timezone():
|
||||
result = format_dt("2026-03-12T02:00:00+00:00", "America/Chicago")
|
||||
assert "CDT" in result or "CST" in result
|
||||
|
||||
|
||||
def test_format_dt_no_seconds_or_microseconds():
|
||||
result = format_dt("2026-03-12T02:30:45.123456+00:00")
|
||||
assert ":45" not in result
|
||||
assert ".123456" not in result
|
||||
assert "10:30 PM" in result
|
||||
|
||||
|
||||
def test_format_dt_single_digit_day():
|
||||
result = format_dt("2026-03-05T03:00:00+00:00")
|
||||
assert "Wed Mar 4," in result
|
||||
assert " 04," not in result
|
||||
|
||||
|
||||
def test_format_dt_single_digit_hour():
|
||||
result = format_dt("2026-01-15T06:00:00+00:00")
|
||||
assert "1:00 AM" in result
|
||||
assert "01:00" not in result
|
||||
Reference in New Issue
Block a user