asTimeZone
function asTimeZone(value): TimeZone;Defined in: timezone.ts:60
Brand a string as a TimeZone. The one tolerated cast: a brand
constructor — the caller guarantees the string was validated first (every
TimeZoneSchema runs isValidTimeZone before calling this).
It checks nothing at runtime, so validate first.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
value |
string |
Returns
Section titled “Returns”Example
Section titled “Example”Validate, then brand
import { asTimeZone, isValidTimeZone, type TimeZone } from "@xtandard/lib/valibot";
function timeZoneFromHeader(value: string | null): TimeZone { const candidate = value ?? "UTC"; return isValidTimeZone({ timeZone: candidate }).valid ? asTimeZone(candidate) : asTimeZone("UTC");}
timeZoneFromHeader("Asia/Tokyo"); // "Asia/Tokyo" (TimeZone)timeZoneFromHeader("Mars/Olympus"); // "UTC"