@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) • 861 B
JavaScript
import { frameNowWallClock, zoneFrame } from "../../internal/zoneFrame.js";
// src/zoned/get/getZonedDay.ts
/**
* Return the current day of month for the specified IANA timeZone.
*
* - Uses nowZonedDateTimeISO() to get the current time.
* - Validation is performed on the timezone.
*
* @param ianaTimezone IANA name or UTC offset: a time zone identifier (`+05:30`, `+0530`, `-08`) or
* a stored offset (`±HH:MM[:SS]`, what `getTimeZoneOffset` returns)
* @returns current day string (zero-padded to 2 digits) or "" on invalid input
*
* @example getZonedDay("Asia/Tokyo") // "29"
* @example getZonedDay("invalid") // ""
*/
function getZonedDay(ianaTimezone) {
const frame = zoneFrame(ianaTimezone);
if (frame === null) return "";
try {
return frameNowWallClock(frame).day.toString().padStart(2, "0");
} catch {
return "";
}
}
export { getZonedDay };