Value to extract timezone from
Optionalopts: { stripTZA?: boolean }OptionalstripTZA?: booleanWhether to strip timezone abbreviations (default: true). TZAs like "PST" are ambiguous and usually stripped.
TzSrc with zone name and provenance, or undefined if no timezone found
// ISO offset strings
extractZone("+08:00")
// { zone: "UTC+8", tz: "UTC+8", src: "offsetMinutesToZoneName" }
extractZone("UTC-5:30")
// { zone: "UTC-5:30", tz: "UTC-5:30", src: "normalizeZone" }
// IANA zone names
extractZone("America/Los_Angeles")
// { zone: "America/Los_Angeles", tz: "America/Los_Angeles", src: "normalizeZone" }
// Timestamps with embedded timezones
extractZone("2023:01:15 10:30:00-08:00")
// { zone: "UTC-8", tz: "UTC-8", src: "offsetMinutesToZoneName",
// leftovers: "2023:01:15 10:30:00" }
// Unicode minus signs
extractZone("−08:00") // Unicode minus (U+2212)
// { zone: "UTC-8", tz: "UTC-8", src: "offsetMinutesToZoneName" }
// Numeric hour offsets
extractZone(-8)
// { zone: "UTC-8", tz: "UTC-8", src: "hourOffset" }
// Arrays (uses first non-null)
extractZone([null, "+05:30", undefined])
// { zone: "UTC+5:30", tz: "UTC+5:30", src: "offsetMinutesToZoneName" }
// Strips timezone abbreviations by default
extractZone("2023:01:15 10:30:00-08:00 PST")
// { zone: "UTC-8", tz: "UTC-8", src: "offsetMinutesToZoneName",
// leftovers: "2023:01:15 10:30:00" }
// Invalid inputs return undefined
extractZone("invalid") // undefined
extractZone(null) // undefined
Extract timezone information from various value types.
Handles multiple input formats and performs intelligent parsing:
By default, strips timezone abbreviations (PST, PDT, etc.) as they are ambiguous. Returns provenance information indicating which parsing method succeeded.
Supports Unicode minus signs (−, U+2212) and plus-minus signs (±, U+00B1) in addition to ASCII +/-.