UNPKG

@modern-kit/utils

Version:
41 lines (37 loc) 1.35 kB
'use strict'; var dateIsAfterDate = require('../isAfterDate/index.cjs'); var dateIsBeforeDate = require('../isBeforeDate/index.cjs'); require('../parseDate/index.cjs'); require('../parseDateString/index.cjs'); function isDateInRange({ targetDate = /* @__PURE__ */ new Date(), fromDate, toDate, inclusive = "from" }) { const compareDate = (date, type) => { const isFrom = type === "from"; const inclusiveToUse = inclusive === "both" || (isFrom ? inclusive === "from" : inclusive === "to"); const compareFunc = isFrom ? dateIsAfterDate.isAfterDate : dateIsBeforeDate.isBeforeDate; return compareFunc({ targetDate, compareDate: date, inclusive: inclusiveToUse }); }; if (fromDate && !toDate) { return compareDate(fromDate, "from"); } if (!fromDate && toDate) { return compareDate(toDate, "to"); } if (fromDate && toDate) { if (dateIsAfterDate.isAfterDate({ targetDate: fromDate, compareDate: toDate })) { throw new Error("fromDate\uAC00 toDate\uBCF4\uB2E4 \uB2A6\uC744 \uC218 \uC5C6\uC2B5\uB2C8\uB2E4."); } return compareDate(fromDate, "from") && compareDate(toDate, "to"); } throw new Error("fromDate \uD639\uC740 toDate \uC911 \uD558\uB098\uB294 \uD544\uC694\uD569\uB2C8\uB2E4."); } exports.isDateInRange = isDateInRange; //# sourceMappingURL=index.cjs.map