collectype / factory/dates/dateCalendar / dateCalendarFactory
dateCalendarFactory<
T,C>(ctx,oper): <K>(field) =>C
Defined in: factory/dates/dateCalendar.ts:40
Creates a predicate filter for date calendar using PredicType.date.calendar.
T
The item type in the collection.
C extends Wherable<T, C>
The Wherable context type (must extend Wherable<T, C>).
C
The context (usually a collection) supporting the where method.
DateCalendarOper
The date calendar operation (e.g., ‘isToday’, ‘isWeekend’, etc.).
Returns a function that takes a field (of type Date on T) and applies the date calendar predicate to filter the context.
<
K>(field):C
K extends string | number | symbol
K
C
// Example: Composing a date calendar filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { dateCalendarFactory } from 'collectype';
type Person = { name: string; birthday: Date };
class PersonFunctions extends BaseFunctions<Person> {
dateIsToday = dateCalendarFactory<Person, this>(this, 'isToday');
}
// Usage:
const people: Person[] = [
{ name: 'Alice', birthday: new Date() },
{ name: 'Bob', birthday: new Date('2000-01-01') }
];
const fn = new PersonFunctions(people);
const filtered = fn.dateIsToday('birthday');
// filtered contains the items where 'birthday' is today