(date: Date | string | number | undefined, opts: Intl.DateTimeFormatOptions = {})
| 14 | } |
| 15 | |
| 16 | export function formatDate(date: Date | string | number | undefined, opts: Intl.DateTimeFormatOptions = {}) { |
| 17 | if (!date) { |
| 18 | return '' |
| 19 | } |
| 20 | |
| 21 | try { |
| 22 | return new Intl.DateTimeFormat(activeLocale(), { |
| 23 | month: opts.month ?? 'long', |
| 24 | day: opts.day ?? 'numeric', |
| 25 | year: opts.year ?? 'numeric', |
| 26 | ...opts |
| 27 | }).format(new Date(date)) |
| 28 | } catch (_err) { |
| 29 | return '' |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | /** Date only, in the active locale. Drop-in for a bare `.toLocaleDateString()`. */ |
| 34 | export function formatDateShort( |
no test coverage detected