Skip to content

Commit 811bfc8

Browse files
authored
feat(app): show dates for older sessions in the command palette (#62314)
1 parent 4a9b2b6 commit 811bfc8

5 files changed

Lines changed: 50 additions & 7 deletions

File tree

‎packages/app/src/settings/workspaces/workspaces.tsx‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,13 @@ export const SettingsWorkspaces: Component<{
196196

197197
if (!updated) return undefined
198198

199-
return getRelativeTime(new Date(updated).toISOString(), language.t)
199+
return getRelativeTime(new Date(updated).toISOString(), language.t, language.intl())
200200
}
201201

202202
const sessionTime = (session: SessionInfo) => {
203203
if (!session.time.updated) return undefined
204204

205-
return getRelativeTime(new Date(session.time.updated).toISOString(), language.t)
205+
return getRelativeTime(new Date(session.time.updated).toISOString(), language.t, language.intl())
206206
}
207207

208208
const inspect = async (directory: string, active: string | undefined, signal?: AbortSignal) => {

‎packages/app/src/shell/commands/dialog.css‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@
8585

8686
.command-palette-meta {
8787
flex-shrink: 0;
88+
font-variant-numeric: tabular-nums;
8889
}
8990

9091
.command-palette-file-path {

‎packages/app/src/shell/commands/dialog.tsx‎

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { getDirectory, getFilename } from "@opencode/util/path"
22
import { FileIcon } from "@opencode/ui/file-icon"
33
import { Dialog, DialogBody } from "@opencode/ui/dialog"
44
import { Keybind } from "@opencode/ui/keybind"
5+
import { Tooltip } from "@opencode/ui/tooltip"
56
import { SearchHighlight, SearchList, type SearchListRow } from "@opencode/ui/search-list"
67
import { createMemo, Match, Show, Switch } from "solid-js"
78
import { createStore } from "solid-js/store"
@@ -252,9 +253,21 @@ function PaletteSessionRow(props: {
252253
fallback={
253254
<Show when={props.item.updated}>
254255
{(updated) => (
255-
<span class="command-palette-meta">
256-
{getRelativeTime(new Date(updated()).toISOString(), props.language.t)}
257-
</span>
256+
<Tooltip
257+
class="shrink-0"
258+
placement="top"
259+
value={new Intl.DateTimeFormat(props.language.intl(), {
260+
day: "numeric",
261+
month: "short",
262+
year: "numeric",
263+
hour: "numeric",
264+
minute: "2-digit",
265+
}).format(updated())}
266+
>
267+
<span class="command-palette-meta">
268+
{getRelativeTime(new Date(updated()).toISOString(), props.language.t, props.language.intl())}
269+
</span>
270+
</Tooltip>
258271
)}
259272
</Show>
260273
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import { afterEach, expect, setSystemTime, test } from "bun:test"
2+
import { getRelativeTime } from "./time"
3+
4+
const now = new Date(2026, 8, 22, 12)
5+
6+
const t = (key: string, params?: Record<string, string | number>) => `${key}:${params?.count ?? ""}`
7+
8+
afterEach(() => {
9+
setSystemTime()
10+
})
11+
12+
test.each([
13+
[30_000, "common.time.justNow:"],
14+
[5 * 60_000, "common.time.minutesAgo.short:5"],
15+
[3 * 3_600_000, "common.time.hoursAgo.short:3"],
16+
[6 * 86_400_000, "common.time.daysAgo.short:6"],
17+
[7 * 86_400_000, "Sep 15"],
18+
[400 * 86_400_000, "Aug 18, 2025"],
19+
])("formats %pms ago", (ago, expected) => {
20+
setSystemTime(now)
21+
22+
expect(getRelativeTime(new Date(now.getTime() - ago).toISOString(), t, "en-US")).toBe(expected)
23+
})

‎packages/app/src/shell/time.ts‎

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ type TimeKey =
66

77
type Translate = (key: TimeKey, params?: Record<string, string | number>) => string
88

9-
export function getRelativeTime(dateString: string, t: Translate): string {
9+
export function getRelativeTime(dateString: string, t: Translate, locale: string): string {
1010
const date = new Date(dateString)
1111
const now = new Date()
1212
const diffMs = now.getTime() - date.getTime()
@@ -21,5 +21,11 @@ export function getRelativeTime(dateString: string, t: Translate): string {
2121

2222
if (diffHours < 24) return t("common.time.hoursAgo.short", { count: diffHours })
2323

24-
return t("common.time.daysAgo.short", { count: diffDays })
24+
if (diffDays < 7) return t("common.time.daysAgo.short", { count: diffDays })
25+
26+
return new Intl.DateTimeFormat(locale, {
27+
day: "numeric",
28+
month: "short",
29+
year: date.getFullYear() === now.getFullYear() ? undefined : "numeric",
30+
}).format(date)
2531
}

0 commit comments

Comments
 (0)