(
{
locale,
formats,
onError,
timeZone,
}: {
locale: string
timeZone?: string
formats: CustomFormats
onError: OnErrorFn
},
type: 'date' | 'time' | 'dateTimeRange',
getDateTimeFormat: Formatters['getDateTimeFormat'],
options: Parameters<IntlFormatters['formatDate']>[1] = {}
)
| 33 | ] |
| 34 | |
| 35 | export function getFormatter( |
| 36 | { |
| 37 | locale, |
| 38 | formats, |
| 39 | onError, |
| 40 | timeZone, |
| 41 | }: { |
| 42 | locale: string |
| 43 | timeZone?: string |
| 44 | formats: CustomFormats |
| 45 | onError: OnErrorFn |
| 46 | }, |
| 47 | type: 'date' | 'time' | 'dateTimeRange', |
| 48 | getDateTimeFormat: Formatters['getDateTimeFormat'], |
| 49 | options: Parameters<IntlFormatters['formatDate']>[1] = {} |
| 50 | ): Intl.DateTimeFormat { |
| 51 | const {format} = options |
| 52 | const defaults = { |
| 53 | ...(timeZone && {timeZone}), |
| 54 | ...(format && getNamedFormat(formats!, type, format, onError)), |
| 55 | } |
| 56 | |
| 57 | let filteredOptions = filterProps( |
| 58 | options, |
| 59 | DATE_TIME_FORMAT_OPTIONS, |
| 60 | defaults |
| 61 | ) as Intl.DateTimeFormatOptions |
| 62 | |
| 63 | if ( |
| 64 | type === 'time' && |
| 65 | !filteredOptions.hour && |
| 66 | !filteredOptions.minute && |
| 67 | !filteredOptions.second && |
| 68 | !filteredOptions.timeStyle && |
| 69 | !filteredOptions.dateStyle |
| 70 | ) { |
| 71 | // Add default formatting options if hour, minute, or second isn't defined. |
| 72 | filteredOptions = {...filteredOptions, hour: 'numeric', minute: 'numeric'} |
| 73 | } |
| 74 | |
| 75 | return getDateTimeFormat(locale, filteredOptions) |
| 76 | } |
| 77 | |
| 78 | export function formatDate( |
| 79 | config: { |
no test coverage detected