@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 { nowZonedDateTimeISO } from "../../internal/temporalCompat/clock.js";
import { getSystemTimeZone } from "../../zoned/get/getSystemTimeZone.js";
// src/plain/get/getDay.ts
/**
* Return the current day of month using the system timeZone.
*
* - Uses nowZonedDateTimeISO() to get current day in system timezone.
* - Returns zero-padded string (e.g., "29").
* - Returns "" when system timezone is unavailable.
*
* @returns current day string (zero-padded) or "" on invalid
*
* @example getDay() // "29"
* @example getDay() // "" (when system timeZone unavailable)
*/
function getDay() {
const timeZone = getSystemTimeZone();
if (!timeZone) return "";
try {
return nowZonedDateTimeISO(timeZone).day.toString().padStart(2, "0");
} catch {
return "";
}
}
export { getDay };