@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.
33 lines (31 loc) • 1.26 kB
JavaScript
import { isValidDate } from "../validate/isValidDate.js";
import { isBeforeDate } from "./isBeforeDate.js";
import { getToday } from "../get/getToday.js";
// src/plain/compare/isPast.ts
/**
* Return true when `value` is strictly before today, per the system clock
* and system timeZone.
*
* - `value === today` returns false — "past" means strictly before, not
* on-or-before.
* - Compares against `getToday()`, so this depends on the **system clock and
* system timeZone**. A caller needing determinism should use `isZonedPast`
* with an explicit timeZone, or compare against an explicit reference with
* `isBeforeDate`.
* - Returns false if `value` is invalid or the system timeZone is unavailable.
*
* @param value ISO PlainDate string
* @returns true if `value` is before today, false on invalid input
*
* @example isPast("2024-03-14") // true, if today is 2024-03-15
* @example isPast("2024-03-15") // false, if today is 2024-03-15 (equal is not past)
* @example isPast("2024-03-16") // false, if today is 2024-03-15
* @example isPast("invalid") // false
*/
function isPast(value) {
if (!isValidDate(value)) return false;
const today = getToday();
if (today === "") return false;
return isBeforeDate(value, today);
}
export { isPast };