You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

31 lines
757 B

import {Predicate, Context} from './predicate';
export class DatePredicate extends Predicate<Date> {
constructor(context?: Context) {
super('date', context);
}
/**
* Test a date to be before another date.
*
* @param date Maximum value.
*/
before(date: Date) {
return this.addValidator({
message: value => `Expected ${value.toISOString()} to be before ${date.toISOString()}`,
validator: value => value.getTime() < date.getTime()
});
}
/**
* Test a date to be before another date.
*
* @param date Minimum value.
*/
after(date: Date) {
return this.addValidator({
message: value => `Expected ${value.toISOString()} to be after ${date.toISOString()}`,
validator: value => value.getTime() > date.getTime()
});
}
}