Skip to content

Commit

Permalink
Fixed empty time case
Browse files Browse the repository at this point in the history
  • Loading branch information
shubham1206agra committed Jan 7, 2025
1 parent c3688b4 commit ed00cdc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/components/TimeModalPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function TimeModalPicker({value, errorText, label, onInputChange = () => {}}: Ti
<TimePicker
defaultValue={value}
onSubmit={updateInput}
shouldValidate={false}
shouldValidateFutureTime={false}
/>
</View>
</ScreenWrapper>
Expand Down
13 changes: 11 additions & 2 deletions src/components/TimePicker/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ type TimePickerProps = {
/** Whether the time value should be validated */
shouldValidate?: boolean;

/** Whether the time value should be validated for future time only */
shouldValidateFutureTime?: boolean;

/** Whether the picker shows hours, minutes, seconds and milliseconds */
showFullFormat?: boolean;
};
Expand Down Expand Up @@ -118,7 +121,10 @@ function clearSelectedValue(
setSelection({start: newCursorPosition, end: newCursorPosition});
}

function TimePicker({defaultValue = '', onSubmit, onInputChange = () => {}, shouldValidate = true, showFullFormat = false}: TimePickerProps, ref: ForwardedRef<TimePickerRef>) {
function TimePicker(
{defaultValue = '', onSubmit, onInputChange = () => {}, shouldValidate = true, shouldValidateFutureTime = true, showFullFormat = false}: TimePickerProps,
ref: ForwardedRef<TimePickerRef>,
) {
const {numberFormat, translate} = useLocalize();
const {isExtraSmallScreenHeight} = useResponsiveLayout();
const styles = useThemeStyles();
Expand Down Expand Up @@ -166,12 +172,15 @@ function TimePicker({defaultValue = '', onSubmit, onInputChange = () => {}, shou
setErrorMessage(translate('common.error.invalidTimeRange'));
return false;
}
if (!shouldValidateFutureTime) {
return true;
}
const isValid = DateUtils.isTimeAtLeastOneMinuteInFuture({timeString, dateTimeString: defaultValue});
setError(!isValid);
setErrorMessage(translate('common.error.invalidTimeShouldBeFuture'));
return isValid;
},
[shouldValidate, hours, minutes, amPmValue, defaultValue, translate],
[shouldValidate, hours, minutes, amPmValue, shouldValidateFutureTime, defaultValue, translate],
);

const resetHours = () => {
Expand Down

0 comments on commit ed00cdc

Please sign in to comment.