@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.
22 lines (20 loc) • 552 B
JavaScript
import { systemTimeZone } from "./resolveLocale.js";
import { nowZonedDateTimeISO } from "./temporalCompat/clock.js";
// src/internal/todayDate.ts
/**
* Today's date in the host's time zone.
*
* @returns the date, or `null` when the host reports no time zone or the clock cannot be read
*
* @example todayDate()?.toString() // "2024-03-10"
*/
function todayDate() {
const timeZone = systemTimeZone();
if (timeZone === "") return null;
try {
return nowZonedDateTimeISO(timeZone).toPlainDate();
} catch {
return null;
}
}
export { todayDate };