20 lines
471 B
TypeScript
20 lines
471 B
TypeScript
export function asDate (d: Date|string): Date {
|
|
if (typeof d === 'string') return new Date(d)
|
|
if (d instanceof Date) return d
|
|
|
|
throw new Error(`Unexpected date value '${JSON.stringify(d)}' !`)
|
|
}
|
|
|
|
const intl = Intl.DateTimeFormat(navigator.language, {
|
|
weekday: 'long',
|
|
month: 'short',
|
|
day: 'numeric',
|
|
hour: 'numeric',
|
|
minute: 'numeric',
|
|
second: 'numeric'
|
|
})
|
|
|
|
export function formatDate (d: Date|string): string {
|
|
d = asDate(d)
|
|
return intl.format(d)
|
|
} |