predictype

predictype v0.8.1


predictype / predicates/dates/dateCalendar / dateCalendar

Function: dateCalendar()

dateCalendar(source, oper, today): boolean

Defined in: predicates/dates/dateCalendar.ts:42

Checks calendar-based properties of a date (UTC) using the specified operation.

Parameters

source

Date

The date to check.

oper

DateCalendarOper

The calendar operation to perform (e.g. ‘is_today’, ‘is_weekend’, ‘is_past’).

today

Date = ...

(optional) The reference date to use as “today” (defaults to new Date()). Useful for testing.

Returns

boolean

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

Throws

If the operation is not recognized.

Example

const today = new Date();
const janFirst = new Date('2025-01-01');

dateCalendar(today, 'is_today'); // true (if run today)
dateCalendar(janFirst, 'is_first_day_of_month'); // true

Remarks

Supported Operators: