mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-20 18:57:17 +03:00
feat(app): show dates for older sessions in the command palette (#62314)
This commit is contained in:
committed by
GitHub
Unverified
parent
4a9b2b69d5
commit
811bfc8e91
@@ -196,13 +196,13 @@ export const SettingsWorkspaces: Component<{
|
||||
|
||||
if (!updated) return undefined
|
||||
|
||||
return getRelativeTime(new Date(updated).toISOString(), language.t)
|
||||
return getRelativeTime(new Date(updated).toISOString(), language.t, language.intl())
|
||||
}
|
||||
|
||||
const sessionTime = (session: SessionInfo) => {
|
||||
if (!session.time.updated) return undefined
|
||||
|
||||
return getRelativeTime(new Date(session.time.updated).toISOString(), language.t)
|
||||
return getRelativeTime(new Date(session.time.updated).toISOString(), language.t, language.intl())
|
||||
}
|
||||
|
||||
const inspect = async (directory: string, active: string | undefined, signal?: AbortSignal) => {
|
||||
|
||||
@@ -85,6 +85,7 @@
|
||||
|
||||
.command-palette-meta {
|
||||
flex-shrink: 0;
|
||||
font-variant-numeric: tabular-nums;
|
||||
}
|
||||
|
||||
.command-palette-file-path {
|
||||
|
||||
@@ -2,6 +2,7 @@ import { getDirectory, getFilename } from "@opencode/util/path"
|
||||
import { FileIcon } from "@opencode/ui/file-icon"
|
||||
import { Dialog, DialogBody } from "@opencode/ui/dialog"
|
||||
import { Keybind } from "@opencode/ui/keybind"
|
||||
import { Tooltip } from "@opencode/ui/tooltip"
|
||||
import { SearchHighlight, SearchList, type SearchListRow } from "@opencode/ui/search-list"
|
||||
import { createMemo, Match, Show, Switch } from "solid-js"
|
||||
import { createStore } from "solid-js/store"
|
||||
@@ -252,9 +253,21 @@ function PaletteSessionRow(props: {
|
||||
fallback={
|
||||
<Show when={props.item.updated}>
|
||||
{(updated) => (
|
||||
<span class="command-palette-meta">
|
||||
{getRelativeTime(new Date(updated()).toISOString(), props.language.t)}
|
||||
</span>
|
||||
<Tooltip
|
||||
class="shrink-0"
|
||||
placement="top"
|
||||
value={new Intl.DateTimeFormat(props.language.intl(), {
|
||||
day: "numeric",
|
||||
month: "short",
|
||||
year: "numeric",
|
||||
hour: "numeric",
|
||||
minute: "2-digit",
|
||||
}).format(updated())}
|
||||
>
|
||||
<span class="command-palette-meta">
|
||||
{getRelativeTime(new Date(updated()).toISOString(), props.language.t, props.language.intl())}
|
||||
</span>
|
||||
</Tooltip>
|
||||
)}
|
||||
</Show>
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
import { afterEach, expect, setSystemTime, test } from "bun:test"
|
||||
import { getRelativeTime } from "./time"
|
||||
|
||||
const now = new Date(2026, 8, 22, 12)
|
||||
|
||||
const t = (key: string, params?: Record<string, string | number>) => `${key}:${params?.count ?? ""}`
|
||||
|
||||
afterEach(() => {
|
||||
setSystemTime()
|
||||
})
|
||||
|
||||
test.each([
|
||||
[30_000, "common.time.justNow:"],
|
||||
[5 * 60_000, "common.time.minutesAgo.short:5"],
|
||||
[3 * 3_600_000, "common.time.hoursAgo.short:3"],
|
||||
[6 * 86_400_000, "common.time.daysAgo.short:6"],
|
||||
[7 * 86_400_000, "Sep 15"],
|
||||
[400 * 86_400_000, "Aug 18, 2025"],
|
||||
])("formats %pms ago", (ago, expected) => {
|
||||
setSystemTime(now)
|
||||
|
||||
expect(getRelativeTime(new Date(now.getTime() - ago).toISOString(), t, "en-US")).toBe(expected)
|
||||
})
|
||||
@@ -6,7 +6,7 @@ type TimeKey =
|
||||
|
||||
type Translate = (key: TimeKey, params?: Record<string, string | number>) => string
|
||||
|
||||
export function getRelativeTime(dateString: string, t: Translate): string {
|
||||
export function getRelativeTime(dateString: string, t: Translate, locale: string): string {
|
||||
const date = new Date(dateString)
|
||||
const now = new Date()
|
||||
const diffMs = now.getTime() - date.getTime()
|
||||
@@ -21,5 +21,11 @@ export function getRelativeTime(dateString: string, t: Translate): string {
|
||||
|
||||
if (diffHours < 24) return t("common.time.hoursAgo.short", { count: diffHours })
|
||||
|
||||
return t("common.time.daysAgo.short", { count: diffDays })
|
||||
if (diffDays < 7) return t("common.time.daysAgo.short", { count: diffDays })
|
||||
|
||||
return new Intl.DateTimeFormat(locale, {
|
||||
day: "numeric",
|
||||
month: "short",
|
||||
year: date.getFullYear() === now.getFullYear() ? undefined : "numeric",
|
||||
}).format(date)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user