Make commit history easier to scan and review (#2146)
* feat(app): improve commit history and diff review * fix(app): keep commit timestamps current * fix(app): pause hidden commit clocks * fix(app): reopen commit diff in persistence test
This commit is contained in:
@@ -1,5 +1,20 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { formatDuration, formatMessageTimestamp } from "./time";
|
||||
import { formatDuration, formatMessageTimestamp, formatTimeAgo } from "./time";
|
||||
|
||||
describe("formatTimeAgo", () => {
|
||||
const now = new Date("2026-07-16T12:00:00.000Z");
|
||||
|
||||
it.each([
|
||||
["2026-07-16T11:59:55.000Z", "just now"],
|
||||
["2026-07-16T11:59:30.000Z", "30s ago"],
|
||||
["2026-07-16T11:55:00.000Z", "5m ago"],
|
||||
["2026-07-16T10:00:00.000Z", "2h ago"],
|
||||
["2026-07-13T12:00:00.000Z", "3d ago"],
|
||||
["2026-01-15T12:00:00.000Z", "Jan 15"],
|
||||
])("formats %s as %s", (date, expected) => {
|
||||
expect(formatTimeAgo(new Date(date), now)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe("formatDuration", () => {
|
||||
it("renders sub-minute durations as whole seconds", () => {
|
||||
|
||||
@@ -2,8 +2,7 @@
|
||||
* Format a date as a human-friendly relative time string
|
||||
* Examples: "just now", "5m ago", "2h ago", "3d ago", "Jan 15"
|
||||
*/
|
||||
export function formatTimeAgo(date: Date): string {
|
||||
const now = new Date();
|
||||
export function formatTimeAgo(date: Date, now: Date = new Date()): string {
|
||||
const diffMs = now.getTime() - date.getTime();
|
||||
const diffSec = Math.floor(diffMs / 1000);
|
||||
const diffMin = Math.floor(diffSec / 60);
|
||||
|
||||
Reference in New Issue
Block a user