(
config: {
locale: string
timeZone?: string
formats: CustomFormats
onError: OnErrorFn
},
getDateTimeFormat: Formatters['getDateTimeFormat'],
value: Parameters<IntlFormatters['formatTime']>[0],
options: Parameters<IntlFormatters['formatTime']>[1] = {}
)
| 99 | } |
| 100 | |
| 101 | export function formatTime( |
| 102 | config: { |
| 103 | locale: string |
| 104 | timeZone?: string |
| 105 | formats: CustomFormats |
| 106 | onError: OnErrorFn |
| 107 | }, |
| 108 | getDateTimeFormat: Formatters['getDateTimeFormat'], |
| 109 | value: Parameters<IntlFormatters['formatTime']>[0], |
| 110 | options: Parameters<IntlFormatters['formatTime']>[1] = {} |
| 111 | ): string { |
| 112 | const date = typeof value === 'string' ? new Date(value || 0) : value |
| 113 | |
| 114 | try { |
| 115 | return getFormatter(config, 'time', getDateTimeFormat, options).format(date) |
| 116 | } catch (e) { |
| 117 | config.onError( |
| 118 | new IntlFormatError('Error formatting time.', config.locale, e) |
| 119 | ) |
| 120 | } |
| 121 | |
| 122 | return String(date) |
| 123 | } |
| 124 | |
| 125 | export function formatDateTimeRange( |
| 126 | config: { |
no test coverage detected