{"version":3,"sources":["../../src/utilities/validateTimezones.ts"],"sourcesContent":["import type { Timezone } from '../config/types.js'\n\nimport { InvalidConfiguration } from '../errors/index.js'\n\ntype ValidateTimezonesArgs = {\n /**\n * The source of the timezones for error messaging\n */\n source?: string\n /**\n * Array of timezones to validate\n */\n timezones: Timezone[] | undefined\n}\n\n/**\n * Validates a UTC offset string.\n * Only supports the ±HH:mm format (e.g., +05:30, -08:00).\n *\n * Valid ranges: hours -12 to +14, minutes 0-59\n *\n * @returns true if the offset is valid\n */\nconst isValidUtcOffset = (value: string): boolean => {\n // Strict format check: only ±HH:mm\n const match = value.match(/^([+-])(\\d{2}):(\\d{2})$/)\n if (!match) {\n return false\n }\n\n const sign = match[1] === '+' ? 1 : -1\n const hours = parseInt(match[2]!, 10)\n const minutes = parseInt(match[3]!, 10)\n\n // Minutes must be 0-59\n if (minutes > 59) {\n return false\n }\n\n // Valid range: -12:00 (-720 min) to +14:00 (+840 min)\n const totalMinutes = sign * (hours * 60 + minutes)\n return totalMinutes >= -720 && totalMinutes <= 840\n}\n\n/**\n * Checks if a timezone is supported by the current runtime.\n * Supports both IANA timezone names and UTC offset formats.\n *\n * For IANA names: Uses Intl.DateTimeFormat and Intl.supportedValuesOf\n * For UTC offsets: Uses native Date API to validate (±HH:mm format only)\n */\nconst isTimezoneSupported = (timezoneValue: string): boolean => {\n // UTC is always supported\n if (timezoneValue === 'UTC') {\n return true\n }\n\n // Check if it's a UTC offset format (starts with + or -)\n if (timezoneValue.startsWith('+') || timezoneValue.startsWith('-')) {\n return isValidUtcOffset(timezoneValue)\n }\n\n // For IANA timezone names, use Intl.DateTimeFormat as primary check\n try {\n new Intl.DateTimeFormat('en-US', { timeZone: timezoneValue })\n return true\n } catch {\n // DateTimeFormat failed, timezone is not supported\n }\n\n // Secondary check: verify against supportedValuesOf if available\n if (typeof Intl.supportedValuesOf === 'function') {\n const supportedTimezones = Intl.supportedValuesOf('timeZone')\n if (supportedTimezones.includes(timezoneValue)) {\n return true\n }\n }\n\n return false\n}\n\n/**\n * Validates that all provided timezones are supported by the current runtime's Intl API.\n * Uses both Intl.DateTimeFormat and Intl.supportedValuesOf for comprehensive validation.\n *\n * @throws InvalidConfiguration if an unsupported timezone is found\n */\nexport const validateTimezones = ({ source, timezones }: ValidateTimezonesArgs): void => {\n if (!timezones?.length) {\n return\n }\n\n for (const timezone of timezones) {\n if (!isTimezoneSupported(timezone.value)) {\n const sourceText = source ? ` in ${source}` : ''\n throw new InvalidConfiguration(\n `Timezone ${timezone.value}${sourceText} is not supported by the current runtime via the Intl API.`,\n )\n }\n }\n}\n"],"names":["InvalidConfiguration","isValidUtcOffset","value","match","sign","hours","parseInt","minutes","totalMinutes","isTimezoneSupported","timezoneValue","startsWith","Intl","DateTimeFormat","timeZone","supportedValuesOf","supportedTimezones","includes","validateTimezones","source","timezones","length","timezone","sourceText"],"mappings":"AAEA,SAASA,oBAAoB,QAAQ,qBAAoB;AAazD;;;;;;;CAOC,GACD,MAAMC,mBAAmB,CAACC;IACxB,mCAAmC;IACnC,MAAMC,QAAQD,MAAMC,KAAK,CAAC;IAC1B,IAAI,CAACA,OAAO;QACV,OAAO;IACT;IAEA,MAAMC,OAAOD,KAAK,CAAC,EAAE,KAAK,MAAM,IAAI,CAAC;IACrC,MAAME,QAAQC,SAASH,KAAK,CAAC,EAAE,EAAG;IAClC,MAAMI,UAAUD,SAASH,KAAK,CAAC,EAAE,EAAG;IAEpC,uBAAuB;IACvB,IAAII,UAAU,IAAI;QAChB,OAAO;IACT;IAEA,sDAAsD;IACtD,MAAMC,eAAeJ,OAAQC,CAAAA,QAAQ,KAAKE,OAAM;IAChD,OAAOC,gBAAgB,CAAC,OAAOA,gBAAgB;AACjD;AAEA;;;;;;CAMC,GACD,MAAMC,sBAAsB,CAACC;IAC3B,0BAA0B;IAC1B,IAAIA,kBAAkB,OAAO;QAC3B,OAAO;IACT;IAEA,yDAAyD;IACzD,IAAIA,cAAcC,UAAU,CAAC,QAAQD,cAAcC,UAAU,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