(
config: {
locale: string
timeZone?: string
formats: CustomFormats
onError: OnErrorFn
},
getDateTimeFormat: Formatters['getDateTimeFormat'],
value: Parameters<IntlFormatters['formatDate']>[0],
options: Parameters<IntlFormatters['formatDate']>[1] = {}
)
| 154 | } |
| 155 | |
| 156 | export function formatDateToParts( |
| 157 | config: { |
| 158 | locale: string |
| 159 | timeZone?: string |
| 160 | formats: CustomFormats |
| 161 | onError: OnErrorFn |
| 162 | }, |
| 163 | getDateTimeFormat: Formatters['getDateTimeFormat'], |
| 164 | value: Parameters<IntlFormatters['formatDate']>[0], |
| 165 | options: Parameters<IntlFormatters['formatDate']>[1] = {} |
| 166 | ): Intl.DateTimeFormatPart[] { |
| 167 | const date = typeof value === 'string' ? new Date(value || 0) : value |
| 168 | try { |
| 169 | return getFormatter( |
| 170 | config, |
| 171 | 'date', |
| 172 | getDateTimeFormat, |
| 173 | options |
| 174 | ).formatToParts(date) as Intl.DateTimeFormatPart[] // TODO: remove this when https://github.com/microsoft/TypeScript/pull/50402 is merged |
| 175 | } catch (e) { |
| 176 | config.onError( |
| 177 | new IntlFormatError('Error formatting date.', config.locale, e) |
| 178 | ) |
| 179 | } |
| 180 | |
| 181 | return [] |
| 182 | } |
| 183 | |
| 184 | export function formatTimeToParts( |
| 185 | config: { |
nothing calls this directly
no test coverage detected