MCPcopy Index your code
hub / github.com/formatjs/formatjs / formatTimeToParts

Function formatTimeToParts

packages/intl/dateTime.ts:184–211  ·  view source on GitHub ↗
(
  config: {
    locale: string
    timeZone?: string
    formats: CustomFormats
    onError: OnErrorFn
  },
  getDateTimeFormat: Formatters['getDateTimeFormat'],
  value: Parameters<IntlFormatters['formatTimeToParts']>[0],
  options: Parameters<IntlFormatters['formatTimeToParts']>[1] = {}
)

Source from the content-addressed store, hash-verified

182}
183
184export 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}

Callers

nothing calls this directly

Calls 2

getFormatterFunction · 0.70
formatToPartsMethod · 0.65

Tested by

no test coverage detected