Files
deepseek-harness/packages/experimental/client-ui-forge/src/client/format.ts
T
LegGasai 2ef4c00dd1 feat(forge): add a compact review list view and quote review comments into the chat
Lay the review page's view menu out like the Session list's, show each list
item's hint on its meta line, add a compact one-line view whose titles
marquee on hover with a hover card of the details, drop Ask Agent, and quote
comments and threads from the changes tab into the change request's
conversation. The Session row title marquee moves to ui-primitives so both
lists share it.

Refs #8312
2026-11-12 12:58:02 +08:00

52 lines
1.9 KiB
TypeScript

/** Localized durations and relative times shown on change request cards. */
import { relativeTime } from '@deepseek-ai/dsh-client-ui-primitives'
import type { PropsLocale } from '@deepseek-ai/dsh-client-ui-slots'
import type { NS } from './locales.ts'
type Translate = PropsLocale<typeof NS>['t']
/**
* Format an elapsed time as hours and minutes, minutes and seconds, or seconds.
* @param ms - elapsed milliseconds.
* @param t - forge panel copy.
* @returns the localized duration.
*/
export function formatDuration(ms: number, t: Translate): string {
const total = Math.round(ms / 1000)
const hours = Math.floor(total / 3600)
const minutes = Math.floor(total % 3600 / 60)
const seconds = total % 60
if (hours > 0) return t('duration.hours', { hours, minutes })
if (minutes > 0) return t('duration.minutes', { minutes, seconds })
return t('duration.seconds', { seconds })
}
/**
* Format how long ago an ISO 8601 time was.
* @param iso - the time.
* @param now - current epoch milliseconds.
* @param t - forge panel copy.
* @returns the localized relative time, or undefined when `iso` does not parse.
*/
export function formatAgo(iso: string, now: number, t: Translate): string | undefined {
const at = Date.parse(iso)
if (!Number.isFinite(at)) return undefined
const { unit, n } = relativeTime(at, now)
return t(`time.${unit}`, { n })
}
/**
* Format how long ago an ISO time was in the compact form a one-line list row shows, such as 5分钟 or 2d.
* @param iso - ISO 8601 time.
* @param now - current epoch milliseconds.
* @param t - forge panel copy.
* @returns the label, or undefined for an unparsable time.
*/
export function formatShortAgo(iso: string, now: number, t: Translate): string | undefined {
const at = Date.parse(iso)
if (!Number.isFinite(at)) return undefined
const { unit, n } = relativeTime(at, now)
return t(`time.short.${unit}`, { n })
}