class-validator-extended
Version:
Additional validators for class-validator.
23 lines (22 loc) • 1.11 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.futureDayjs = futureDayjs;
const dayjs_1 = __importDefault(require("dayjs"));
const is_dayjs_1 = require("../../type/is-dayjs");
/**
* @category Predicates
* @param value The value to validate.
* @param options Additional options (see {@link FutureDayjs}).
*/
function futureDayjs(value, options) {
var _a, _b;
const now = (0, dayjs_1.default)();
const inclusive = (_a = options === null || options === void 0 ? void 0 : options.inclusive) !== null && _a !== void 0 ? _a : false;
const granularity = (_b = options === null || options === void 0 ? void 0 : options.granularity) !== null && _b !== void 0 ? _b : 'milliseconds';
// Let's not rely on the isSameOrBefore-plugin which might or might not be registered.
return ((0, is_dayjs_1.isDayjs)(value, options) &&
(value.isAfter(now, granularity) || (inclusive && value.isSame(now, granularity))));
}