diff options
| author | Adam Malczewski <[email protected]> | 2026-09-07 18:00:14 +0900 |
|---|---|---|
| committer | Adam Malczewski <[email protected]> | 2026-09-07 18:00:14 +0900 |
| commit | 61733924352285df6c44f66edf69ea6f738fae3e (patch) | |
| tree | ef607006b55002e988b1e37cb3680b28f087482c /src/features | |
| parent | 48b23a8132537209c338aa04311f8057b1f5f5b5 (diff) | |
| download | dispatch-web-61733924352285df6c44f66edf69ea6f738fae3e.tar.gz dispatch-web-61733924352285df6c44f66edf69ea6f738fae3e.zip | |
feat(workspaces): tile stat line shows months instead of a short date
The relative last-activity time switched to an MM/DD date once past a week.
Now it stays relative: days continue to a month (30 days), then months
("10d", "29d", "1mo", "2mo", ...). A month ≈ 30 days; the label never
becomes an absolute date.
Verification: svelte-check 0 errors/0 warnings; vitest 1694/1694; biome
clean on touched files; build ok.
Diffstat (limited to 'src/features')
| -rw-r--r-- | src/features/workspaces/logic/view-model.test.ts | 13 | ||||
| -rw-r--r-- | src/features/workspaces/logic/view-model.ts | 10 |
2 files changed, 13 insertions, 10 deletions
diff --git a/src/features/workspaces/logic/view-model.test.ts b/src/features/workspaces/logic/view-model.test.ts index d283481..d13f485 100644 --- a/src/features/workspaces/logic/view-model.test.ts +++ b/src/features/workspaces/logic/view-model.test.ts @@ -49,10 +49,15 @@ describe("relativeTime", () => { expect(relativeTime(now - 3 * 24 * 60 * 60_000, now)).toBe("3d"); }); - it("is a short date beyond a week", () => { - // 7+ days ago: just check it is a MM/DD string. - const s = relativeTime(now - 10 * 24 * 60 * 60_000, now); - expect(s).toMatch(/^\d{2}\/\d{2}$/); + it("keeps days past a week (no short date) up to a month", () => { + expect(relativeTime(now - 10 * 24 * 60 * 60_000, now)).toBe("10d"); + expect(relativeTime(now - 29 * 24 * 60 * 60_000, now)).toBe("29d"); + }); + + it("is months past a month", () => { + expect(relativeTime(now - 30 * 24 * 60 * 60_000, now)).toBe("1mo"); + expect(relativeTime(now - 75 * 24 * 60 * 60_000, now)).toBe("2mo"); + expect(relativeTime(now - 365 * 24 * 60 * 60_000, now)).toBe("12mo"); }); }); diff --git a/src/features/workspaces/logic/view-model.ts b/src/features/workspaces/logic/view-model.ts index 0b9f239..6f5a635 100644 --- a/src/features/workspaces/logic/view-model.ts +++ b/src/features/workspaces/logic/view-model.ts @@ -96,10 +96,8 @@ export function relativeTime(then: number, now: number): string { const hours = Math.floor(mins / 60); if (hours < 24) return `${hours}h`; const days = Math.floor(hours / 24); - if (days < 7) return `${days}d`; - // Beyond a week: a short date (MM/DD). Uses UTC parts for determinism in tests. - const d = new Date(then); - const month = String(d.getUTCMonth() + 1).padStart(2, "0"); - const day = String(d.getUTCDate()).padStart(2, "0"); - return `${month}/${day}`; + if (days < 30) return `${days}d`; + // Past a month: months (a month ≈ 30 days). No short date — the label + // stays relative forever. + return `${Math.floor(days / 30)}mo`; } |
