MCPcopy
hub / github.com/formatjs/formatjs / IsValidTimeZoneName

Function IsValidTimeZoneName

packages/ecma402-abstract/IsValidTimeZoneName.ts:57–92  ·  view source on GitHub ↗
(
  tz: string,
  {
    zoneNamesFromData,
    uppercaseLinks,
  }: {
    zoneNamesFromData: readonly string[]
    uppercaseLinks: Record<string, string>
  }
)

Source from the content-addressed store, hash-verified

55 * @returns true if timeZone is a valid identifier
56 */
57export function IsValidTimeZoneName(
58 tz: string,
59 {
60 zoneNamesFromData,
61 uppercaseLinks,
62 }: {
63 zoneNamesFromData: readonly string[]
64 uppercaseLinks: Record<string, string>
65 }
66): boolean {
67 // 1. If IsTimeZoneOffsetString(timeZone) is true, return true
68 // Per ECMA-402 PR #788, UTC offset identifiers are valid
69 if (IsTimeZoneOffsetString(tz)) {
70 return true
71 }
72
73 // 2. Let timeZones be AvailableNamedTimeZoneIdentifiers()
74 // 3. If timeZones contains an element equal to timeZone, return true
75 // NOTE: Implementation uses case-insensitive comparison per spec note
76 const uppercasedTz = tz.toUpperCase()
77 const zoneNames = new Set()
78 const linkNames = new Set()
79
80 zoneNamesFromData.map(z => z.toUpperCase()).forEach(z => zoneNames.add(z))
81 Object.keys(uppercaseLinks).forEach(linkName => {
82 linkNames.add(linkName.toUpperCase())
83 zoneNames.add(uppercaseLinks[linkName].toUpperCase())
84 })
85
86 if (zoneNames.has(uppercasedTz) || linkNames.has(uppercasedTz)) {
87 return true
88 }
89
90 // 4. Return false
91 return false
92}

Callers 3

InitializeDateTimeFormatFunction · 0.85
core.tsFile · 0.85

Calls 1

IsTimeZoneOffsetStringFunction · 0.70

Tested by

no test coverage detected