UNPKG

class-validator-extended

Version:
34 lines (33 loc) 1.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.FUTURE_DATE = void 0; exports.FutureDate = FutureDate; const class_validator_1 = require("class-validator"); const future_date_predicate_1 = require("./future-date.predicate"); /** @hidden */ exports.FUTURE_DATE = 'futureDate'; /** * Checks if the given value is a Date object in the future. * * Beware that the behaviour of this check depends on the current time and can thus be difficult to test. In particular, * as time goes by the property can become invalid without ever changing its value. * * #### Example * ```typescript * // Ensure the value is in the future. * @FutureDay() * scheduledFor: Date * ``` * * @category Date * @param options Generic class-validator options. */ function FutureDate(options) { return (0, class_validator_1.ValidateBy)({ name: exports.FUTURE_DATE, validator: { validate: (value, _arguments) => (0, future_date_predicate_1.futureDate)(value), defaultMessage: (0, class_validator_1.buildMessage)(eachPrefix => `${eachPrefix}$property must be a Date instance in the future`, options), }, }, options); }