parseUnitFromTime
Signature
Section titled “Signature”parseUnitFromTime(value: string, unit: SmallestUnit<"hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond">): stringReturn a specific time unit extracted from a PlainTime string.
- Extracts “hour”, “minute”, “second”, “millisecond”, “microsecond” or “nanosecond” from a PlainTime.
- Returns zero-padded string for hour, minute, second (2 digits) and millisecond, microsecond and nanosecond (3 digits, each the 0-999 Temporal field).
unitaccepts the singular or plural name ("hour"or"hours"), as Temporal does.- Returns "" for invalid input.
Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
value | string | ISO PlainTime string |
unit | SmallestUnit<"hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond"> | unit to extract from the time |
Returns
Section titled “Returns”string representation of the requested unit or "" on invalid input
Examples
Section titled “Examples”import { parseUnitFromTime } from "@northguild/gmt/plain/parse";
parseUnitFromTime("14:30:45.123", "hour") // "14"