MCPcopy Create free account
hub / github.com/ZingerLittleBee/ServerBee / formatDate

Function formatDate

apps/web/src/lib/format.ts:16–31  ·  view source on GitHub ↗
(date: Date | string | number | undefined, opts: Intl.DateTimeFormatOptions = {})

Source from the content-addressed store, hash-verified

14}
15
16export 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()`. */
34export function formatDateShort(

Callers 1

DataTableDateFilterFunction · 0.90

Calls 1

activeLocaleFunction · 0.85

Tested by

no test coverage detected