(
{
locale,
formats,
onError,
}: {
locale: string
formats: CustomFormats
onError: OnErrorFn
},
getRelativeTimeFormat: Formatters['getRelativeTimeFormat'],
options: Parameters<IntlFormatters['formatRelativeTime']>[2] = {}
)
| 14 | > = ['numeric', 'style'] |
| 15 | |
| 16 | function getFormatter( |
| 17 | { |
| 18 | locale, |
| 19 | formats, |
| 20 | onError, |
| 21 | }: { |
| 22 | locale: string |
| 23 | formats: CustomFormats |
| 24 | onError: OnErrorFn |
| 25 | }, |
| 26 | getRelativeTimeFormat: Formatters['getRelativeTimeFormat'], |
| 27 | options: Parameters<IntlFormatters['formatRelativeTime']>[2] = {} |
| 28 | ): Intl.RelativeTimeFormat { |
| 29 | const {format} = options |
| 30 | |
| 31 | const defaults = |
| 32 | (!!format && getNamedFormat(formats, 'relative', format, onError)) || {} |
| 33 | const filteredOptions = filterProps( |
| 34 | options, |
| 35 | RELATIVE_TIME_FORMAT_OPTIONS, |
| 36 | defaults as Intl.RelativeTimeFormatOptions |
| 37 | ) as Intl.RelativeTimeFormatOptions |
| 38 | |
| 39 | return getRelativeTimeFormat(locale, filteredOptions) |
| 40 | } |
| 41 | |
| 42 | export function formatRelativeTime( |
| 43 | config: { |
no test coverage detected