(
config: {
locale: string
timeZone?: string
formats: CustomFormats
onError: OnErrorFn
},
getDateTimeFormat: Formatters['getDateTimeFormat'],
value: Parameters<IntlFormatters['formatDate']>[0],
options: Parameters<IntlFormatters['formatDate']>[1] = {}
)
| 76 | } |
| 77 | |
| 78 | export function formatDate( |
| 79 | config: { |
| 80 | locale: string |
| 81 | timeZone?: string |
| 82 | formats: CustomFormats |
| 83 | onError: OnErrorFn |
| 84 | }, |
| 85 | getDateTimeFormat: Formatters['getDateTimeFormat'], |
| 86 | value: Parameters<IntlFormatters['formatDate']>[0], |
| 87 | options: Parameters<IntlFormatters['formatDate']>[1] = {} |
| 88 | ): string { |
| 89 | const date = typeof value === 'string' ? new Date(value || 0) : value |
| 90 | try { |
| 91 | return getFormatter(config, 'date', getDateTimeFormat, options).format(date) |
| 92 | } catch (e) { |
| 93 | config.onError( |
| 94 | new IntlFormatError('Error formatting date.', config.locale, e) |
| 95 | ) |
| 96 | } |
| 97 | |
| 98 | return String(date) |
| 99 | } |
| 100 | |
| 101 | export function formatTime( |
| 102 | config: { |
no test coverage detected