@burglekitt/gmt
Version:
Temporal-based date and time utilities with timezone support and polyfill integration
28 lines (27 loc) • 1.18 kB
TypeScript
import type { DateTimeUnit } from "../../types/index.js";
type NowUnit = DateTimeUnit | "dayOfWeek";
/**
* Return the requested current unit value using the system timeZone.
*
* - Valid units: "year", "month", "week", "day", "dayOfWeek", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond".
* - Uses Temporal.Now.zonedDateTimeISO to get current time in system timezone.
* - Returns "" when unit is invalid or system timezone is unavailable.
*
* @param unit unit to extract from current local time
* @returns string representation of the requested unit or "" on invalid
*
* @example getNowUnit("year") // "2024"
* @example getNowUnit("month") // "03"
* @example getNowUnit("week") // "11"
* @example getNowUnit("day") // "15"
* @example getNowUnit("dayOfWeek") // "5"
* @example getNowUnit("hour") // "14"
* @example getNowUnit("minute") // "30"
* @example getNowUnit("second") // "45"
* @example getNowUnit("millisecond") // "000"
* @example getNowUnit("microsecond") // "000"
* @example getNowUnit("nanosecond") // "000"
* @example getNowUnit("invalid") // ""
*/
export declare function getNowUnit(unit: NowUnit): string;
export {};