UNPKG

@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.

25 lines (23 loc) • 705 B
import { nowZonedDateTimeISO } from "../../internal/temporalCompat/clock.js"; import { getSystemTimeZone } from "../../zoned/get/getSystemTimeZone.js"; // src/plain/get/getToday.ts /** * Return the current PlainDate as an ISO string in the system timeZone. * * - Uses nowZonedDateTimeISO() to get current date in system timezone. * - Returns "" when system timezone is unavailable. * * @returns ISO 8601 PlainDate string or "" on error * * @example getToday() // "2024-03-15" (current date) */ function getToday() { const timeZone = getSystemTimeZone(); if (!timeZone) return ""; try { return nowZonedDateTimeISO(timeZone).toPlainDate().toString(); } catch { return ""; } } export { getToday };