predictype
Version:
PredicType is a library of pre-built and tested predicates for TypeScript, covering various data types and operations.
31 lines (30 loc) • 1.26 kB
TypeScript
import { DateComparisonOper } from '../../enums/dates.js';
/**
* Compares two dates in UTC using the specified comparison operation.
*
* @param source The first date to compare.
* @param oper The comparison operation to perform (e.g. 'after', 'before', 'equals').
* @param target The second date to compare against.
* @returns True if the comparison is valid according to the operator, otherwise false.
*
* @throws {Error} 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:
* - **AFTER**: Is the first date after the second?
* - **AFTER_OR_EQUAL**: After or equal to the second date?
* - **BEFORE**: Is the first date before the second?
* - **BEFORE_OR_EQUAL**: Before or equal to the second date?
* - **EQUALS**: Are the dates equal?
* - **NOT_EQUALS**: Are the dates not equal?
* - **SAME_DAY**: Are the dates on the same day?
* - **SAME_MONTH**: Are the dates in the same month?
* - **SAME_YEAR**: Are the dates in the same year?
*/
export declare function dateComparison(source: Date, oper: DateComparisonOper, target: Date): boolean;