collectype / factory/dates/dateRange / dateRangeFactory
dateRangeFactory<
T,C>(ctx,oper): <K>(field,min,max) =>C
Defined in: factory/dates/dateRange.ts:41
Creates a predicate filter for date range using PredicType.date.range.
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.
DateRangeOper
The date range operation (e.g., ‘between’, ‘notBetween’, etc.).
Returns a function that takes a field (of type Date on T), a min and max value, and applies the date range predicate to filter the context.
<
K>(field,min,max):C
K extends string | number | symbol
K
Date
Date
C
// Example: Composing a date range filter as a property, homogeneous model
import { BaseFunctions } from 'collectype';
import { dateRangeFactory } from 'collectype';
type Person = { name: string; birthday: Date };
class PersonFunctions extends BaseFunctions<Person> {
dateBetween = dateRangeFactory<Person, this>(this, 'between');
}
// Usage:
const people: Person[] = [
{ name: 'Alice', birthday: new Date('2000-01-01') },
{ name: 'Bob', birthday: new Date('2010-01-01') },
{ name: 'Charlie', birthday: new Date('2020-01-01') }
];
const fn = new PersonFunctions(people);
const filtered = fn.dateBetween('birthday', new Date('2000-01-01'), new Date('2015-01-01'));
// filtered contains the items where 'birthday' is between 2000 and 2015