UNPKG

@mui/x-date-pickers-pro

Version:

The Pro plan edition of the MUI X Date and Time Picker components.

48 lines (43 loc) 1.11 kB
import { validateTime } from '@mui/x-date-pickers/validation'; import { isRangeValid } from "../internals/utils/date-utils.js"; import { rangeValueManager } from "../internals/utils/valueManagers.js"; /** * Validation props used by the Time Range Picker and Time Range Field. */ /** * Validation props as received by the validateTimeRange method. */ /** * Name of the props that should be defaulted before being passed to the validateTimeRange method. */ export const validateTimeRange = ({ adapter, value, timezone, props }) => { const [start, end] = value; const dateTimeValidations = [validateTime({ adapter, value: start, timezone, props }), validateTime({ adapter, value: end, timezone, props })]; if (dateTimeValidations[0] || dateTimeValidations[1]) { return dateTimeValidations; } // for partial input if (start === null || end === null) { return [null, null]; } if (!isRangeValid(adapter, value)) { return ['invalidRange', 'invalidRange']; } return [null, null]; }; validateTimeRange.valueManager = rangeValueManager;