(
config: {
locale: string
timeZone?: string
formats: CustomFormats
onError: OnErrorFn
},
getDateTimeFormat: Formatters['getDateTimeFormat'],
value: Parameters<IntlFormatters['formatTimeToParts']>[0],
options: Parameters<IntlFormatters['formatTimeToParts']>[1] = {}
)
| 182 | } |
| 183 | |
| 184 | export function formatTimeToParts( |
| 185 | config: { |
| 186 | locale: string |
| 187 | timeZone?: string |
| 188 | formats: CustomFormats |
| 189 | onError: OnErrorFn |
| 190 | }, |
| 191 | getDateTimeFormat: Formatters['getDateTimeFormat'], |
| 192 | value: Parameters<IntlFormatters['formatTimeToParts']>[0], |
| 193 | options: Parameters<IntlFormatters['formatTimeToParts']>[1] = {} |
| 194 | ): Intl.DateTimeFormatPart[] { |
| 195 | const date = typeof value === 'string' ? new Date(value || 0) : value |
| 196 | |
| 197 | try { |
| 198 | return getFormatter( |
| 199 | config, |
| 200 | 'time', |
| 201 | getDateTimeFormat, |
| 202 | options |
| 203 | ).formatToParts(date) as Intl.DateTimeFormatPart[] // TODO: remove this when https://github.com/microsoft/TypeScript/pull/50402 is merged |
| 204 | } catch (e) { |
| 205 | config.onError( |
| 206 | new IntlFormatError('Error formatting time.', config.locale, e) |
| 207 | ) |
| 208 | } |
| 209 | |
| 210 | return [] |
| 211 | } |
nothing calls this directly
no test coverage detected