@mui/x-date-pickers
Version:
The community edition of the Date and Time Picker components (MUI X).
50 lines (49 loc) • 1.68 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.validateDate = void 0;
var _dateUtils = require("../internals/utils/date-utils");
var _valueManagers = require("../internals/utils/valueManagers");
const validateDate = ({
props,
value,
timezone,
adapter
}) => {
if (value === null) {
return null;
}
const {
shouldDisableDate,
shouldDisableMonth,
shouldDisableYear,
disablePast,
disableFuture
} = props;
const now = adapter.utils.date(undefined, timezone);
const minDate = (0, _dateUtils.applyDefaultDate)(adapter.utils, props.minDate, adapter.defaultDates.minDate);
const maxDate = (0, _dateUtils.applyDefaultDate)(adapter.utils, props.maxDate, adapter.defaultDates.maxDate);
switch (true) {
case !adapter.utils.isValid(value):
return 'invalidDate';
case Boolean(shouldDisableDate && shouldDisableDate(value)):
return 'shouldDisableDate';
case Boolean(shouldDisableMonth && shouldDisableMonth(value)):
return 'shouldDisableMonth';
case Boolean(shouldDisableYear && shouldDisableYear(value)):
return 'shouldDisableYear';
case Boolean(disableFuture && adapter.utils.isAfterDay(value, now)):
return 'disableFuture';
case Boolean(disablePast && adapter.utils.isBeforeDay(value, now)):
return 'disablePast';
case Boolean(minDate && adapter.utils.isBeforeDay(value, minDate)):
return 'minDate';
case Boolean(maxDate && adapter.utils.isAfterDay(value, maxDate)):
return 'maxDate';
default:
return null;
}
};
exports.validateDate = validateDate;
validateDate.valueManager = _valueManagers.singleItemValueManager;
;