UNPKG

@modern-kit/utils

Version:
39 lines (36 loc) 1.26 kB
import { isAfterDate } from '../isAfterDate/index.mjs'; import { isBeforeDate } from '../isBeforeDate/index.mjs'; import '../parseDate/index.mjs'; import '../parseDateString/index.mjs'; 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 ? isAfterDate : 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 (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."); } export { isDateInRange }; //# sourceMappingURL=index.mjs.map