MCPcopy
hub / github.com/formatjs/formatjs / findIntervalFormat

Function findIntervalFormat

packages/intl-datetimeformat/core.ts:341–359  ·  view source on GitHub ↗

* GH #4535: When a format skeleton uses raw pattern form (e.g., "MMMEd, h:mm a") * instead of canonical form (e.g., "MMMEd, hm"), interval formats won't match * by exact key. This function finds the matching canonical interval format by * normalizing the time portion of the skeleton.

(
  skeleton: string,
  intervalFormats: Record<string, any>
)

Source from the content-addressed store, hash-verified

339 * normalizing the time portion of the skeleton.
340 */
341function findIntervalFormat(
342 skeleton: string,
343 intervalFormats: Record<string, any>
344): Record<string, string> | undefined {
345 const commaIdx = skeleton.indexOf(', ')
346 if (commaIdx === -1) return undefined
347 const datePart = skeleton.slice(0, commaIdx)
348 const timePart = skeleton.slice(commaIdx + 2)
349 // Canonicalize the time part: strip non-skeleton chars (colons, spaces),
350 // remove AM/PM markers (a/b/B are implied by h/K hour symbols),
351 // and collapse repeated field chars (hh→h, mm→m, ss→s)
352 const canonical = timePart
353 .replace(/[^a-zA-Z]/g, '')
354 .replace(/[abB]/g, '')
355 .replace(/(.)\1+/g, '$1')
356 if (canonical === timePart) return undefined
357 const canonicalKey = `${datePart}, ${canonical}`
358 return intervalFormats[canonicalKey]
359}
360
361DateTimeFormat.__addLocaleData = function __addLocaleData(
362 ...data: RawDateTimeLocaleData[]

Callers 1

core.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected