@@ -109,27 +109,34 @@ export function getRelativeTime(
109109 ? 'short'
110110 : 'long' ,
111111 }
112+ try {
113+ // eslint-disable-next-line compat/compat
114+ const relativeTimeFormatter = new Intl . RelativeTimeFormat (
115+ locale ,
116+ relativeTimeOptions
117+ )
112118
113- const relativeTimeFormatter = new Intl . RelativeTimeFormat (
114- locale ,
115- relativeTimeOptions
116- )
117-
118- const nowDate =
119- relativeTimeReference instanceof Date
120- ? relativeTimeReference
121- : typeof relativeTimeReference === 'function'
122- ? relativeTimeReference ( )
123- : new Date ( )
119+ const nowDate =
120+ relativeTimeReference instanceof Date
121+ ? relativeTimeReference
122+ : typeof relativeTimeReference === 'function'
123+ ? relativeTimeReference ( )
124+ : new Date ( )
124125
125- const msDateDifference = date . getTime ( ) - nowDate . getTime ( )
126- const timeUnit = getTimeUnit ( msDateDifference )
126+ const msDateDifference = date . getTime ( ) - nowDate . getTime ( )
127+ const timeUnit = getTimeUnit ( msDateDifference )
127128
128- const timeUnitDifference = Math . round (
129- msDateDifference / timeUnitsInMs [ timeUnit ]
130- )
129+ const timeUnitDifference = Math . round (
130+ msDateDifference / timeUnitsInMs [ timeUnit ]
131+ )
131132
132- return relativeTimeFormatter . format ( timeUnitDifference , timeUnit )
133+ return relativeTimeFormatter . format ( timeUnitDifference , timeUnit )
134+ } catch ( error ) {
135+ return formatDate ( date , {
136+ locale,
137+ options : dateStyle ? { dateStyle } : undefined ,
138+ } )
139+ }
133140}
134141
135142/**
0 commit comments