feat(audit): every row keeps its date; dividers for Today, Yesterday, Last 7 days, Older (#5214)
The operator found "Today 08:03" in place of a date odd on the audit log,
and asked for the recency groups as dividers instead. |when now always
writes the date ("Thu 8 Oct 08:03"); mark_day_groups gives each entry its
group in the reader's zone, and a divider row opens each group. A scrolled
page carries the group the last one ended in, so it is not opened twice.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -57,7 +57,8 @@ def test_ago_of_nothing_and_of_another_zone():
|
||||
assert 'title="Tue 6 Oct 2026 18:00:00 UTC"' in str(f.ago(NOW.astimezone(est), now=NOW))
|
||||
|
||||
|
||||
# Milestone 490: a moment in the reader's own zone, on a 24-hour clock.
|
||||
# Milestone 490: a moment in the reader's own zone, on a 24-hour clock, always
|
||||
# with its date: "Today" and "Yesterday" are dividers, never the time (#5214).
|
||||
NY = f.zone("America/New_York")
|
||||
|
||||
|
||||
@@ -67,14 +68,14 @@ def test_ago_hovers_the_moment_in_the_readers_zone():
|
||||
|
||||
|
||||
@pytest.mark.parametrize("moment, text, title", [
|
||||
(NOW - timedelta(hours=1), "Today 13:00", "Tue 6 Oct 2026 13:00:00 EDT"),
|
||||
(NOW - timedelta(hours=1), "Tue 6 Oct 13:00", "Tue 6 Oct 2026 13:00:00 EDT"),
|
||||
# 03:30 UTC on the 6th is 23:30 on the 5th in New York: the zone moves the day.
|
||||
(datetime(2026, 10, 6, 3, 30, tzinfo=timezone.utc), "Yesterday 23:30", "Mon 5 Oct 2026 23:30:00 EDT"),
|
||||
(datetime(2026, 10, 7, 6, 0, tzinfo=timezone.utc), "Tomorrow 02:00", "Wed 7 Oct 2026 02:00:00 EDT"),
|
||||
(datetime(2026, 10, 6, 3, 30, tzinfo=timezone.utc), "Mon 5 Oct 23:30", "Mon 5 Oct 2026 23:30:00 EDT"),
|
||||
(datetime(2026, 10, 7, 6, 0, tzinfo=timezone.utc), "Wed 7 Oct 02:00", "Wed 7 Oct 2026 02:00:00 EDT"),
|
||||
(datetime(2026, 9, 30, 12, 0, tzinfo=timezone.utc), "Wed 30 Sep 08:00", "Wed 30 Sep 2026 08:00:00 EDT"),
|
||||
# Before this year the year shows; in winter the zone is EST, an hour further back.
|
||||
(datetime(2025, 12, 25, 12, 0, tzinfo=timezone.utc), "25 Dec 2025 07:00", "Thu 25 Dec 2025 07:00:00 EST"),
|
||||
(datetime(2026, 10, 6, 21, 5), "Today 17:05", "Tue 6 Oct 2026 17:05:00 EDT"), # naive is UTC
|
||||
(datetime(2026, 10, 6, 21, 5), "Tue 6 Oct 17:05", "Tue 6 Oct 2026 17:05:00 EDT"), # naive is UTC
|
||||
])
|
||||
def test_when_writes_the_exact_moment_in_the_readers_zone(moment, text, title):
|
||||
stamp = moment.replace(tzinfo=timezone.utc) if moment.tzinfo is None else moment
|
||||
@@ -83,11 +84,24 @@ def test_when_writes_the_exact_moment_in_the_readers_zone(moment, text, title):
|
||||
|
||||
|
||||
def test_when_is_a_24_hour_clock_and_utc_without_a_zone():
|
||||
assert ">Today 18:00<" in str(f.when(NOW, now=NOW))
|
||||
assert ">Today 23:59<" in str(f.when(NOW.replace(hour=23, minute=59), now=NOW))
|
||||
assert ">Tue 6 Oct 18:00<" in str(f.when(NOW, now=NOW))
|
||||
assert ">Tue 6 Oct 23:59<" in str(f.when(NOW.replace(hour=23, minute=59), now=NOW))
|
||||
assert str(f.when(None)) == "—"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("moment, group", [
|
||||
(NOW - timedelta(hours=1), "Today"),
|
||||
(datetime(2026, 10, 6, 3, 30, tzinfo=timezone.utc), "Yesterday"), # 23:30 on the 5th in New York
|
||||
(datetime(2026, 10, 5, 3, 30, tzinfo=timezone.utc), "Last 7 days"),
|
||||
(datetime(2026, 9, 30, 12, 0, tzinfo=timezone.utc), "Last 7 days"), # six days back
|
||||
(datetime(2026, 9, 29, 12, 0, tzinfo=timezone.utc), "Older"), # seven
|
||||
(datetime(2025, 12, 25, 12, 0, tzinfo=timezone.utc), "Older"),
|
||||
])
|
||||
def test_day_group_counts_calendar_days_in_the_readers_zone(moment, group):
|
||||
assert f.day_group(moment, NY, now=NOW) == group
|
||||
assert group in f.DAY_GROUPS
|
||||
|
||||
|
||||
def test_zone_falls_back_to_utc_and_names_itself():
|
||||
assert f.zone(None) is timezone.utc and f.zone("") is timezone.utc
|
||||
assert f.zone("Not/AZone") is timezone.utc and f.zone("../etc/passwd") is timezone.utc
|
||||
|
||||
Reference in New Issue
Block a user