* 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> )
| 339 | * normalizing the time portion of the skeleton. |
| 340 | */ |
| 341 | function 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 | |
| 361 | DateTimeFormat.__addLocaleData = function __addLocaleData( |
| 362 | ...data: RawDateTimeLocaleData[] |