@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
26 lines • 2.01 kB
TypeScript
/**
* The range text with the carrier's zone names replaced by the requested ones (defect D16,
* ICU-20548: an affected engine keeps the `short` zone name in a range and drops the requested
* width). Pure over strings, so a test can feed it the text an engine really returned.
*
* Each hit is attributed to an endpoint by a GMT rule, the same attribution `repairRangeParts` reads
* off the parts (CORE-112):
*
* - Carrier names that differ: a name printed for one endpoint only is that endpoint's
* (ECMA-402 PartitionDateTimeRangePattern gives each part one source). The longer name is found
* first, so a name inside the other is not a second hit.
* - Carrier names that are equal: two hits are the start's then the end's, because an interval
* pattern writes the start's fields before the end's (UTS #35 Part 4 §2.6); one hit is a shared
* part and takes the start's; no hit or more than two cannot be attributed.
*
* @param text the carrier's `formatRange` text
* @param carrierNames the carrier's zone name at the start and at the end
* @param wantedNames the requested zone name at the start and at the end
* @returns the repaired text, or `null` when a zone name cannot be given to an endpoint
*
* @example repairRangeText("28/03/2026, 12:00 GMT – 30/03/2026, 13:00 BST", ["GMT", "BST"], ["Greenwich Mean Time", "British Summer Time"]) // "28/03/2026, 12:00 Greenwich Mean Time – 30/03/2026, 13:00 British Summer Time"
* @example repairRangeText("12:00–13:00 GMT", ["GMT", "GMT"], ["GMT+00:00", "GMT+00:00"]) // "12:00–13:00 GMT+00:00" (one shared hit)
* @example repairRangeText("12:00–13:00", ["GMT", "GMT"], ["GMT+00:00", "GMT+00:00"]) // null (no hit)
* @example repairRangeText("12:00–13:00", [undefined, "GMT"], ["a", "b"]) // null (no carrier name)
*/
export declare function repairRangeText(text: string, carrierNames: readonly [string | undefined, string | undefined], wantedNames: readonly [string | undefined, string | undefined]): string | null;