@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.
31 lines (29 loc) • 1.06 kB
JavaScript
import { Temporal } from "../../internal/temporal.js";
import { plainDateOf } from "../../internal/inputChecks.js";
// src/plain/compare/isAfterDate.ts
/**
* Return true if the first ISO PlainDate string represents a date after the second.
*
* - Uses Temporal.PlainDate.compare to compare dates.
* - Returns false if either input is invalid.
*
* @param value1 first ISO PlainDate string
* @param value2 second ISO PlainDate string
* @returns boolean indicating whether value1 is after value2
*
* @example isAfterDate("2024-03-01", "2024-02-29") // true
* @example isAfterDate("2024-02-28", "2024-02-29") // false
* @example isAfterDate("invalid", "2024-02-29") // false
* @example isAfterDate("2024-02-29", "invalid") // false
*/
function isAfterDate(value1, value2) {
const value1Parsed = plainDateOf(value1);
const value2Parsed = plainDateOf(value2);
if (value1Parsed === null || value2Parsed === null) return false;
try {
return Temporal.PlainDate.compare(value1Parsed, value2Parsed) === 1;
} catch {
return false;
}
}
export { isAfterDate };