2026-08-25 11:42:17 +02:00
|
|
|
/** Human-readable date for display; returns an empty string when unset. */
|
2026-08-25 14:23:09 +02:00
|
|
|
export function formatDate(value: string | null | undefined, locale = 'en-GB'): string {
|
2026-08-25 11:42:17 +02:00
|
|
|
if (!value) return ''
|
2026-08-25 14:23:09 +02:00
|
|
|
return new Intl.DateTimeFormat(locale, { dateStyle: 'long' }).format(new Date(value))
|
2026-08-25 11:42:17 +02:00
|
|
|
}
|
|
|
|
|
|
2026-08-25 15:30:57 +02:00
|
|
|
/** Date and time of publication, shown in the article byline. */
|
|
|
|
|
export function formatDateTime(value: string | null | undefined, locale = 'en-GB'): string {
|
|
|
|
|
if (!value) return ''
|
|
|
|
|
return new Intl.DateTimeFormat(locale, { dateStyle: 'long', timeStyle: 'short' })
|
|
|
|
|
.format(new Date(value))
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-25 11:42:17 +02:00
|
|
|
/** Machine-readable date for the `datetime` attribute and structured data. */
|
|
|
|
|
export function isoDate(value: string | null | undefined): string {
|
|
|
|
|
return value ? new Date(value).toISOString() : ''
|
|
|
|
|
}
|