stupa-pdf-api/frontend/node_modules/@mui/x-date-pickers/internals/utils/validation/validateTime.js

51 lines
1.9 KiB
JavaScript

import { createIsAfterIgnoreDatePart } from '../time-utils';
export const validateTime = ({
adapter,
value,
props
}) => {
if (value === null) {
return null;
}
const {
minTime,
maxTime,
minutesStep,
shouldDisableClock,
shouldDisableTime,
disableIgnoringDatePartForTimeValidation = false,
disablePast,
disableFuture,
timezone
} = props;
const now = adapter.utils.dateWithTimezone(undefined, timezone);
const isAfter = createIsAfterIgnoreDatePart(disableIgnoringDatePartForTimeValidation, adapter.utils);
switch (true) {
case !adapter.utils.isValid(value):
return 'invalidDate';
case Boolean(minTime && isAfter(minTime, value)):
return 'minTime';
case Boolean(maxTime && isAfter(value, maxTime)):
return 'maxTime';
case Boolean(disableFuture && adapter.utils.isAfter(value, now)):
return 'disableFuture';
case Boolean(disablePast && adapter.utils.isBefore(value, now)):
return 'disablePast';
case Boolean(shouldDisableTime && shouldDisableTime(value, 'hours')):
return 'shouldDisableTime-hours';
case Boolean(shouldDisableTime && shouldDisableTime(value, 'minutes')):
return 'shouldDisableTime-minutes';
case Boolean(shouldDisableTime && shouldDisableTime(value, 'seconds')):
return 'shouldDisableTime-seconds';
case Boolean(shouldDisableClock && shouldDisableClock(adapter.utils.getHours(value), 'hours')):
return 'shouldDisableClock-hours';
case Boolean(shouldDisableClock && shouldDisableClock(adapter.utils.getMinutes(value), 'minutes')):
return 'shouldDisableClock-minutes';
case Boolean(shouldDisableClock && shouldDisableClock(adapter.utils.getSeconds(value), 'seconds')):
return 'shouldDisableClock-seconds';
case Boolean(minutesStep && adapter.utils.getMinutes(value) % minutesStep !== 0):
return 'minutesStep';
default:
return null;
}
};