parseUnitFromUtc
Signature
Section titled “Signature”parseUnitFromUtc(value: string, unit: UtcUnit, optionsArg?: { weekStartsOn?: "monday" | "sunday"; }): stringimport { parseUnitFromUtc } from "@northguild/gmt/utc/parse";Extract a unit from a UTC datetime string.
- Valid units: “year”, “month”, “week”, “day”, “dayOfWeek”, “hour”, “minute”, “second”, “millisecond”.
- Uses Temporal.Instant.from to parse, converts to UTC.
- Returns “” for invalid input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value |
string |
ISO UTC datetime string (e.g., “2024-03-17T14:30:45Z”) |
unit |
UtcUnit |
unit to extract from the datetime |
Options
Section titled “Options”options
| Option | Type | Default |
|---|---|---|
weekStartsOn? |
"monday" | "sunday" |
— |
Returns
Section titled “Returns”string representation of the requested unit or “” on invalid input
Related types
Section titled “Related types”Examples
Section titled “Examples”parseUnitFromUtc("2024-03-17T14:30:45Z", "month") // "03"parseUnitFromUtc("2024-01-01T00:00:00Z", "week") // "1"parseUnitFromUtc("2024-01-01T00:00:00Z", "week", { weekStartsOn: "sunday" }) // "1"parseUnitFromUtc("invalid", "month") // ""