collectype / factory/dates/dateComparison / dateComparisonFactory
dateComparisonFactory<
T,C>(ctx,oper): <K>(field,target) =>C
Defined in: factory/dates/dateComparison.ts:41
Creates a predicate filter for date comparison using PredicType.date.comparison.
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.
DateComparisonOper
The date comparison operation (e.g., ‘equals’, ‘before’, ‘after’, etc.).
Returns a function that takes a field (of type Date on T) and a target value, and applies the date comparison predicate to filter the context.
<
K>(field,target):C
K extends string | number | symbol
K
Date
C
// Example: Composing a date comparison filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { dateComparisonFactory } from 'collectype';
type Person = { name: string; birthday: Date };
class PersonFunctions extends BaseFunctions<Person> {
dateSameYear = dateComparisonFactory<Person, this>(this, 'same_year');
}
// Usage:
const people: Person[] = [
{ name: 'Alice', birthday: new Date('2000-01-01') },
{ name: 'Bob', birthday: new Date('2000-12-31') },
{ name: 'Charlie', birthday: new Date('2010-01-01') }
];
const fn = new PersonFunctions(people);
const filtered = fn.dateSameYear('birthday', new Date('2000-06-15'));
// filtered contains the items where 'birthday' is in the same year as June 15, 2000