//#region src/timezone.ts
/** The neutral zero-offset zone — the listing fallback, never a host's chosen default. */
const UTC = "UTC";
/**
* Narrow an arbitrary string to `IanaTimezone`. Trust-boundary validator: a zone string
* from a user / API is unsafe until this returns true. Empty → false; unknown zone → false.
*/
function isValidTimezone(tz) {
	if (!tz) return false;
	try {
		new Intl.DateTimeFormat(void 0, { timeZone: tz });
		return true;
	} catch {
		return false;
	}
}
let cachedZones;
/**
* All IANA zones the runtime supports, sorted ascending. Memoized + frozen — the set is
* static per runtime, so the `Intl.supportedValuesOf` call + sort run once and the returned
* snapshot is immutable (mutate a copy). Falls back to `[UTC]` where `supportedValuesOf` is absent.
*/
function listSupportedTimezones() {
	if (cachedZones) return cachedZones;
	const intlWithSupported = Intl;
	const zones = intlWithSupported.supportedValuesOf ? intlWithSupported.supportedValuesOf("timeZone") : ["UTC"];
	cachedZones = Object.freeze([...zones].sort());
	return cachedZones;
}
/**
* Group zones by IANA continent prefix (`Europe/Paris` → `Europe`); a zone with no `/`
* (e.g. `UTC`) lands in `Other`. For rendering a grouped zone-picker.
*/
function groupTimezonesByContinent(zones) {
	const out = {};
	for (const zone of zones) {
		const continent = zone.includes("/") ? zone.slice(0, zone.indexOf("/")) : "Other";
		(out[continent] ??= []).push(zone);
	}
	return out;
}
//#endregion
export { UTC, groupTimezonesByContinent, isValidTimezone, listSupportedTimezones };
