@mui/x-date-pickers-pro
Version:
The Pro plan edition of the Date and Time Picker components (MUI X).
46 lines (45 loc) • 1.36 kB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
const _excluded = ["shouldDisableDate"];
import { validateDate } from '@mui/x-date-pickers/validation';
import { isRangeValid } from "../internals/utils/date-utils.js";
import { rangeValueManager } from "../internals/utils/valueManagers.js";
export const validateDateRange = ({
adapter,
value,
timezone,
props
}) => {
const [start, end] = value;
const {
shouldDisableDate
} = props,
otherProps = _objectWithoutPropertiesLoose(props, _excluded);
const dateValidations = [validateDate({
adapter,
value: start,
timezone,
props: _extends({}, otherProps, {
shouldDisableDate: day => !!shouldDisableDate?.(day, 'start')
})
}), validateDate({
adapter,
value: end,
timezone,
props: _extends({}, otherProps, {
shouldDisableDate: day => !!shouldDisableDate?.(day, 'end')
})
})];
if (dateValidations[0] || dateValidations[1]) {
return dateValidations;
}
// for partial input
if (start === null || end === null) {
return [null, null];
}
if (!isRangeValid(adapter.utils, value)) {
return ['invalidRange', 'invalidRange'];
}
return [null, null];
};
validateDateRange.valueManager = rangeValueManager;