@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
20 lines (19 loc) • 981 B
TypeScript
export type ZonedParseUnit = "year" | "month" | "week" | "day" | "dayOfWeek" | "hour" | "minute" | "second" | "millisecond" | "nanosecond" | "timeZone";
/**
* 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.
*
* @param value zoned ISO 8601 datetime string
* @param unit unit to extract
* @param options optional settings (e.g. weekStartsOn for week calculations)
* @returns string representation of the requested unit or "" when invalid
*
* @example parseUnitFromZoned("2024-02-29T12:34:56.789+00:00[UTC]", "year") // "2024"
* @example parseUnitFromZoned("invalid", "year") // ""
*/
export declare function parseUnitFromZoned(value: string, unit: ZonedParseUnit, optionsArg?: {
weekStartsOn?: "monday" | "sunday";
}): string;