Line data Source code
1 : import { useI18n } from 'vue-i18n'
2 :
3 : /** Formats an ISO timestamp as a long localized UTC date, or '' when it is missing or invalid. */
4 12 : export function useLongDate() {
5 12 : const { d } = useI18n()
6 :
7 0 : function longDate(raw: string | null | undefined): string {
8 0 : const date = raw ? new Date(raw) : null
9 0 : if (!date || Number.isNaN(date.getTime())) return ''
10 0 : return d(date, {
11 : year: 'numeric',
12 : month: 'long',
13 : day: 'numeric',
14 : timeZone: 'UTC'
15 : })
16 : }
17 :
18 12 : return { longDate }
19 : }
|