parseUnitFromZoned
Signature
Section titled “Signature”parseUnitFromZoned(value: string, unit: ZonedParseUnit, optionsArg?: { weekStartsOn?: "monday" | "sunday"; }): stringimport { parseUnitFromZoned } from "@northguild/gmt/zoned/parse";Return the requested unit value from an ISO 8601 zoned datetime string.
- Valid units: “year”, “month”, “week”, “day”, “dayOfWeek”, “hour”, “minute”, “second”, “millisecond”, “nanosecond”, “timeZone”.
- Uses Temporal.ZonedDateTime.from to parse.
- Returns “” for invalid input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
zoned ISO 8601 datetime string |
unit |
ZonedParseUnit |
unit to extract |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
weekStartsOn? |
"monday" | "sunday" |
— |
Returns
Section titled “Returns”string representation of the requested unit or “” when invalid
Related types
Section titled “Related types”Examples
Section titled “Examples”parseUnitFromZoned("2024-02-29T12:34:56.789+00:00[UTC]", "year") // "2024"parseUnitFromZoned("invalid", "year") // ""