diff --git a/lintunes/__init__.py b/lintunes/__init__.py index 8d26a7f..41b262c 100644 --- a/lintunes/__init__.py +++ b/lintunes/__init__.py @@ -1,3 +1,3 @@ """LinTunes — iTunes-style music library manager and player for Linux.""" -__version__ = "0.80.0" +__version__ = "0.81.0" diff --git a/lintunes/gui/track_table.py b/lintunes/gui/track_table.py index 713e679..92f6fad 100644 --- a/lintunes/gui/track_table.py +++ b/lintunes/gui/track_table.py @@ -186,8 +186,8 @@ ALL_COLUMNS = [ ("rating", "Rating", 80), ("date_added", "Date Added", 140), ("date_modified", "Date Modified", 140), - ("play_date_utc", "Last Played", 140), - ("skip_date", "Last Skipped", 140), + ("play_date_utc", "Last Played", 175), # date and time + ("skip_date", "Last Skipped", 175), ("bit_rate", "Bit Rate", 60), ("sample_rate", "Sample Rate", 80), ("composer", "Composer", 150), @@ -382,8 +382,30 @@ def _format_size(size: int) -> str: return f"{mb:.1f} MB" -def _format_date(iso_str: str) -> str: - return iso_str[:10] if iso_str else "" +# Columns that show the time of day too, as iTunes did for these two. +TIMED_DATES = ("play_date_utc", "skip_date") + + +def _format_date(iso_str: str, with_time: bool = False) -> str: + """A stored date — UTC, ISO 8601, with or without a "Z" (LinTunes, the + iTunes import and the Rabbit all stamp UTC) — as this machine's local + date, plus "9:41 PM" with ``with_time``. A late-evening play used to + show tomorrow's date, the UTC one.""" + if not iso_str: + return "" + from datetime import datetime, timezone + try: + when = datetime.fromisoformat(iso_str.replace("Z", "+00:00")) + except ValueError: + return iso_str[:10] + if when.tzinfo is None: + when = when.replace(tzinfo=timezone.utc) + when = when.astimezone() + text = when.strftime("%Y-%m-%d") + if with_time: + hour = when.hour % 12 or 12 + text += f" {hour}:{when.minute:02d} {'AM' if when.hour < 12 else 'PM'}" + return text # Now-playing speaker pixmaps, cached per (playing, color) @@ -689,7 +711,7 @@ class TrackTableModel(QAbstractTableModel): if field == "size": return _format_size(value) if field in ("date_added", "play_date_utc", "skip_date", "date_modified"): - return _format_date(value or "") + return _format_date(value or "", field in TIMED_DATES) if isinstance(value, int) and value == 0: return "" return str(value) if value else "" diff --git a/tests/test_round113.py b/tests/test_round113.py new file mode 100644 index 0000000..e02a5ab --- /dev/null +++ b/tests/test_round113.py @@ -0,0 +1,32 @@ +"""Round 113: Last Played and Last Skipped show the time, in local time.""" +import time + +import pytest + +from lintunes.gui.track_table import _format_date + + +@pytest.fixture +def new_york(monkeypatch): + monkeypatch.setenv("TZ", "America/New_York") + time.tzset() + yield + monkeypatch.undo() + time.tzset() + + +def test_last_played_shows_local_date_and_time(new_york): + # 01:30 UTC on the 26th is 9:30 PM on the 25th in New York (EDT). + assert _format_date("2026-10-26T01:30:12.5", True) == "2026-10-25 9:30 PM" + assert _format_date("2026-10-26T01:30:12Z", True) == "2026-10-25 9:30 PM" + assert _format_date("2026-07-04T16:05:00", True) == "2026-07-04 12:05 PM" + assert _format_date("2026-07-04T04:05:00", True) == "2026-07-04 12:05 AM" + + +def test_plain_dates_are_local_too_without_a_time(new_york): + assert _format_date("2026-10-26T01:30:12") == "2026-10-25" + + +def test_nothing_or_nonsense(new_york): + assert _format_date("", True) == "" + assert _format_date("sometime 2026", True) == "sometime 2"