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

Function formatDateToParts

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

Source from the content-addressed store, hash-verified

154}
155
156export 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
184export function formatTimeToParts(
185 config: {

Callers

nothing calls this directly

Calls 2

getFormatterFunction · 0.70
formatToPartsMethod · 0.65

Tested by

no test coverage detected