UNPKG

fluent-ts-validator

Version:
45 lines 1.82 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); /** * Validates if the given date lies between the lower and upper boundary. * * It can be specified whether the lower and/or upper boundary should be in- or excluded. * * '(' indicates exclusion of the lower boundary. * '[' indicates inclusion of the lower boundary. * ')' indicates exclusion of the upper boundary. * ']' indicates inclusion of the upper boundary. * * The IsBetweenValidator defaults to exclusion - (). * * @export * @class IsBetweenValidator * @implements {PropertyValidator<Date>} */ class IsBetweenValidator { constructor(lowerDate, upperDate, lowerBoundary = "(", upperBoundary = ")") { this.lowerDate = lowerDate; this.upperDate = upperDate; this.lowerBoundary = lowerBoundary; this.upperBoundary = upperBoundary; } isValid(input) { if (typeof input === "undefined" || input === null) { return false; } else if (this.lowerBoundary === "[" && this.upperBoundary === "]") { return this.lowerDate.getTime() <= input.getTime() && input.getTime() <= this.upperDate.getTime(); } else if (this.lowerBoundary === "[" && this.upperBoundary === ")") { return this.lowerDate.getTime() <= input.getTime() && input.getTime() < this.upperDate.getTime(); } else if (this.lowerBoundary === "(" && this.upperBoundary === "]") { return this.lowerDate.getTime() < input.getTime() && input.getTime() <= this.upperDate.getTime(); } else { return this.lowerDate.getTime() < input.getTime() && input.getTime() < this.upperDate.getTime(); } } } exports.IsBetweenValidator = IsBetweenValidator; //# sourceMappingURL=IsBetweenValidator.js.map