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.

23 lines (21 loc) • 769 B
import { Temporal } from "./temporal.js"; import { plainDateOf } from "./inputChecks.js"; import { todayDate } from "./todayDate.js"; // src/internal/compareToToday.ts /** * How a date compares with today in the host's time zone. * * @param value an ISO `PlainDate` string * @returns `-1` before today, `0` today, `1` after today, or `null` for an invalid date or when the host reports no time zone or clock * * @example compareToToday("2024-03-14") // -1, if today is 2024-03-15 * @example compareToToday("invalid") // null */ function compareToToday(value) { const date = plainDateOf(value); if (date === null) return null; const today = todayDate(); if (today === null) return null; return Temporal.PlainDate.compare(date, today); } export { compareToToday };