mirror of
https://github.com/anomalyco/opencode.git
synced 2026-11-26 23:28:43 +00:00
32 lines
808 B
TypeScript
32 lines
808 B
TypeScript
export function createSessionContextFormatter(locale: string) {
|
|
// The fields luxon's DATETIME_MED preset passed to Intl; output is identical.
|
|
const dateTime = new Intl.DateTimeFormat(locale, {
|
|
year: "numeric",
|
|
month: "short",
|
|
day: "numeric",
|
|
hour: "numeric",
|
|
minute: "numeric",
|
|
})
|
|
|
|
return {
|
|
number(value: number | null | undefined) {
|
|
if (value === undefined) return "—"
|
|
|
|
if (value === null) return "—"
|
|
|
|
return value.toLocaleString(locale)
|
|
},
|
|
percent(value: number | null | undefined) {
|
|
if (value === undefined) return "—"
|
|
|
|
if (value === null) return "—"
|
|
|
|
return value.toLocaleString(locale) + "%"
|
|
},
|
|
time(value: number | undefined) {
|
|
if (!value) return "—"
|
|
|
|
return dateTime.format(value)
|
|
},
|
|
}
|
|
}
|