@arco-design/web-vue
Version:
Arco Design Vue 2.0: A Vue.js 3 UI Library
66 lines (65 loc) • 2.08 kB
JavaScript
import { isUndefined, isArray, isDayjs } from "../../_utils/is.js";
function newArray(length) {
return [...Array(length)];
}
function normalizeRangeValue(value) {
if (isUndefined(value)) {
return void 0;
}
return isArray(value) ? value : [value, void 0];
}
function isCompleteRangeValue(value) {
return !!value && isDayjs(value[0]) && isDayjs(value[1]);
}
function isValidRangeValue(value) {
return isUndefined(value) || value.length === 0 || isCompleteRangeValue(value);
}
function mergeValueWithTime(defaultValue, dateValue, timeValue) {
const dateVal = dateValue || defaultValue;
const timeVal = timeValue || defaultValue;
return timeVal.set("year", dateVal.year()).set("month", dateVal.month()).set("date", dateVal.date());
}
function isDisabledDate(cellDate, disabledDate, mode = "date") {
if (typeof disabledDate !== "function")
return false;
const checkDate = (date) => disabledDate(date.toDate());
switch (mode) {
case "date":
case "week":
return checkDate(cellDate);
case "month": {
const days = cellDate.daysInMonth();
for (let d = 1; d <= days; d++) {
if (!checkDate(cellDate.date(d)))
return false;
}
return true;
}
case "quarter": {
const startMonth = Math.floor(cellDate.month() / 3) * 3;
for (let m = startMonth; m < startMonth + 3; m++) {
const monthDate = cellDate.month(m);
const days = monthDate.daysInMonth();
for (let d = 1; d <= days; d++) {
if (!checkDate(monthDate.date(d)))
return false;
}
}
return true;
}
case "year": {
for (let m = 0; m < 12; m++) {
const monthDate = cellDate.month(m);
const days = monthDate.daysInMonth();
for (let d = 1; d <= days; d++) {
if (!checkDate(monthDate.date(d)))
return false;
}
}
return true;
}
default:
return false;
}
}
export { isCompleteRangeValue, isDisabledDate, isValidRangeValue, mergeValueWithTime, newArray, normalizeRangeValue };