predictype

predictype v0.8.1


predictype / predicates/dates / dateComparison

Function: dateComparison()

dateComparison(source, oper, target): boolean

Defined in: predicates/dates/dateComparison.ts:41

Compares two dates in UTC using the specified comparison operation.

Parameters

source

Date

The first date to compare.

oper

DateComparisonOper

The comparison operation to perform (e.g. ‘after’, ‘before’, ‘equals’).

target

Date

The second date to compare against.

Returns

boolean

True if the comparison is valid according to the operator, otherwise false.

Throws

If the operation is not recognized.

Example

const d1 = new Date('2025-01-01');
const d2 = new Date('2025-01-02');
dateComparison(d1, 'before', d2); // true
dateComparison(d1, 'equals', d1); // true

Remarks

Supported Operators: