UNPKG

temporal-extra

Version:

Locale-aware date utilities for Temporal: week numbers, date adjusters, polyfill support and more

41 lines (40 loc) 1.28 kB
/** * Returns true if the Temporal is equal to the reference. * * This comparator is different from the Temporal's `equals` method, as it only * compares the point in time, ignoring the calendar system. */ export const isEqual = (temporal, reference) => { return compare(temporal, reference) === 0; }; /** * Returns true if the Temporal is before the reference. */ export const isBefore = (temporal, reference) => { return compare(temporal, reference) < 0; }; /** * Returns true if the Temporal is before or equal to the reference. */ export const isBeforeOrEqual = (temporal, reference) => { return compare(temporal, reference) <= 0; }; /** * Returns true if the Temporal is after the reference. */ export const isAfter = (temporal, reference) => { return compare(temporal, reference) > 0; }; /** * Returns true if the Temporal is after or equal to the reference. */ export const isAfterOrEqual = (temporal, reference) => { return compare(temporal, reference) >= 0; }; const compare = (temporal, reference) => { if (temporal.constructor !== reference.constructor) { throw new TypeError("Both values must be of the same Temporal type"); } const ctor = temporal.constructor; return ctor.compare(temporal, reference); };