UNPKG

@northguild/gmt

Version:

Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.

24 lines • 1.33 kB
import { Temporal } from "../../internal/temporal.js"; /** * Return 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). * - `unit` accepts the singular or plural name (`"hour"` or `"hours"`), as Temporal does. * - Returns "" for invalid input. * * @param value ISO PlainTime string * @param unit unit to extract from the time * @returns string representation of the requested unit or "" on invalid input * * @example parseUnitFromTime("14:30:45.123", "hour") // "14" * @example parseUnitFromTime("14:30:45.123", "minute") // "30" * @example parseUnitFromTime("14:30:45.123", "second") // "45" * @example parseUnitFromTime("14:30:45.123", "millisecond") // "123" * @example parseUnitFromTime("14:30:45.123", "milliseconds") // "123" * @example parseUnitFromTime("14:30:45.123456789", "nanosecond") // "789" * @example parseUnitFromTime("invalid", "hour") // "" */ export declare function parseUnitFromTime(value: string, unit: Temporal.SmallestUnit<"hour" | "minute" | "second" | "millisecond" | "microsecond" | "nanosecond">): string;