@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.
27 lines (25 loc) • 784 B
JavaScript
import { nowPlainDateTimeISO } from "../../internal/temporalCompat/clock.js";
import { getSystemTimeZone } from "../../zoned/get/getSystemTimeZone.js";
// src/plain/get/getHour.ts
/**
* Return the current hour using the system timeZone.
*
* - Uses nowPlainDateTimeISO() to get current hour in system timezone.
* - Returns zero-padded string (e.g., "14").
* - Returns "" when system timezone is unavailable.
*
* @returns current hour string (zero-padded) or "" on invalid
*
* @example getHour() // "00"
* @example getHour() // "" (when system timeZone unavailable)
*/
function getHour() {
const timeZone = getSystemTimeZone();
if (!timeZone) return "";
try {
return nowPlainDateTimeISO(timeZone).hour.toString().padStart(2, "0");
} catch {
return "";
}
}
export { getHour };