v0.81.0: Last Played and Last Skipped show the time, and every date column shows the local date

This commit is contained in:
2026-10-25 23:40:12 -07:00
parent f410fb8ea1
commit 1fd7dacf88
3 changed files with 60 additions and 6 deletions
+1 -1
View File
@@ -1,3 +1,3 @@
"""LinTunes — iTunes-style music library manager and player for Linux.""" """LinTunes — iTunes-style music library manager and player for Linux."""
__version__ = "0.80.0" __version__ = "0.81.0"
+27 -5
View File
@@ -186,8 +186,8 @@ ALL_COLUMNS = [
("rating", "Rating", 80), ("rating", "Rating", 80),
("date_added", "Date Added", 140), ("date_added", "Date Added", 140),
("date_modified", "Date Modified", 140), ("date_modified", "Date Modified", 140),
("play_date_utc", "Last Played", 140), ("play_date_utc", "Last Played", 175), # date and time
("skip_date", "Last Skipped", 140), ("skip_date", "Last Skipped", 175),
("bit_rate", "Bit Rate", 60), ("bit_rate", "Bit Rate", 60),
("sample_rate", "Sample Rate", 80), ("sample_rate", "Sample Rate", 80),
("composer", "Composer", 150), ("composer", "Composer", 150),
@@ -382,8 +382,30 @@ def _format_size(size: int) -> str:
return f"{mb:.1f} MB" return f"{mb:.1f} MB"
def _format_date(iso_str: str) -> str: # Columns that show the time of day too, as iTunes did for these two.
return iso_str[:10] if iso_str else "" 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) # Now-playing speaker pixmaps, cached per (playing, color)
@@ -689,7 +711,7 @@ class TrackTableModel(QAbstractTableModel):
if field == "size": if field == "size":
return _format_size(value) return _format_size(value)
if field in ("date_added", "play_date_utc", "skip_date", "date_modified"): 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: if isinstance(value, int) and value == 0:
return "" return ""
return str(value) if value else "" return str(value) if value else ""
+32
View File
@@ -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"