Files
Starlight_Lancher/apps/telemetry-dashboard/utils/format.ts

36 lines
985 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

export function formatNumber(value: number): string {
return new Intl.NumberFormat('zh-CN').format(value)
}
export function formatUtcDay(value: string): string {
const parsed = new Date(`${value}T00:00:00.000Z`)
return Number.isNaN(parsed.getTime())
? value
: new Intl.DateTimeFormat('zh-CN', {
month: 'numeric',
day: 'numeric',
timeZone: 'UTC',
}).format(parsed)
}
export function formatUtcTimestamp(value: string): string {
const parsed = new Date(value)
return Number.isNaN(parsed.getTime())
? value
: `${new Intl.DateTimeFormat('zh-CN', {
month: '2-digit',
day: 'numeric',
year: 'numeric',
hour: '2-digit',
minute: '2-digit',
hour12: false,
timeZone: 'UTC',
}).format(parsed)}UTC`
}
export function statusCode(error: unknown): number | null {
if (!error || typeof error !== 'object') return null
const value = error as { statusCode?: number; status?: number }
return value.statusCode ?? value.status ?? null
}