Source

dateTime/isDateBetween.js

"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var isDate_1 = __importDefault(require("./isDate"));
var isUndef_1 = __importDefault(require("../validators/isUndef"));
/**
 * Check if `date` is between `start` and `end`.
 * `start` and `end` are count as datetime (in ms)
 *
 * @author Sandy Lau https://github.com/sandylau333
 *
 * @param date
 * @param start (optional)
 * @param end (optional)
 * @param isInclusive (optional) Default false
 * @category dateTime
 * @module isDateBetween
 */
var isDateBetween = function (date, start, end, isInclusive) {
    if (!(0, isDate_1.default)(date))
        return false;
    var startLimit = (0, isUndef_1.default)(start) || !(0, isDate_1.default)(start) ? 0 : start.valueOf();
    var endLimit = (0, isUndef_1.default)(end) || !(0, isDate_1.default)(end) ? Infinity : end.valueOf();
    var dateValue = date.valueOf();
    if (isInclusive)
        return startLimit <= dateValue && dateValue <= endLimit;
    return startLimit < dateValue && dateValue < endLimit;
};
exports.default = isDateBetween;