Skip to content

Commit

Permalink
Merge pull request #40853 from nkdengineer/fix/40495
Browse files Browse the repository at this point in the history
Fix can't update the custom time of the status to 00:59
  • Loading branch information
arosiclair committed Apr 25, 2024
2 parents 1abbf42 + 9248646 commit f9b05c0
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 12 deletions.
16 changes: 13 additions & 3 deletions src/components/TimePicker/TimePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ function TimePicker({defaultValue = '', onSubmit, onInputChange = () => {}}: Tim
const canUseTouchScreen = DeviceCapabilities.canUseTouchScreen();

const [isError, setError] = useState(false);
const [errorMessage, setErrorMessage] = useState('');
const [selectionHour, setSelectionHour] = useState({start: 0, end: 0});
const [selectionMinute, setSelectionMinute] = useState({start: 2, end: 2}); // we focus it by default so need to have selection on the end
const [hours, setHours] = useState(() => DateUtils.get12HourTimeObjectFromDate(value).hour);
Expand All @@ -129,8 +130,17 @@ function TimePicker({defaultValue = '', onSubmit, onInputChange = () => {}}: Tim

const validate = useCallback(
(time: string) => {
const isValid = DateUtils.isTimeAtLeastOneMinuteInFuture({timeString: time || `${hours}:${minutes} ${amPmValue}`, dateTimeString: defaultValue});
const timeString = time || `${hours}:${minutes} ${amPmValue}`;
const [hourStr] = timeString.split(/[:\s]+/);
const hour = parseInt(hourStr, 10);
if (hour === 0) {
setError(true);
setErrorMessage('common.error.invalidTimeRange');
return false;
}
const isValid = DateUtils.isTimeAtLeastOneMinuteInFuture({timeString, dateTimeString: defaultValue});
setError(!isValid);
setErrorMessage('common.error.invalidTimeShouldBeFuture');
return isValid;
},
[hours, minutes, amPmValue, defaultValue],
Expand Down Expand Up @@ -523,8 +533,8 @@ function TimePicker({defaultValue = '', onSubmit, onInputChange = () => {}}: Tim
{isError ? (
<FormHelpMessage
isError={isError}
message="common.error.invalidTimeShouldBeFuture"
style={styles.pl5}
message={errorMessage}
style={[styles.ph5]}
/>
) : (
<View style={styles.formHelperMessage} />
Expand Down
1 change: 1 addition & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ export default {
enterMerchant: 'Enter a merchant name',
enterAmount: 'Enter an amount',
enterDate: 'Enter a date',
invalidTimeRange: 'Please enter a time using the 12-hour clock format (e.g., 2:30 PM).',
},
comma: 'comma',
semicolon: 'semicolon',
Expand Down
1 change: 1 addition & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ export default {
enterMerchant: 'Introduce un comerciante',
enterAmount: 'Introduce un importe',
enterDate: 'Introduce una fecha',
invalidTimeRange: 'Por favor, introduce una hora entre 1 y 12 (por ejemplo, 2:30 PM).',
},
comma: 'la coma',
semicolon: 'el punto y coma',
Expand Down
9 changes: 0 additions & 9 deletions src/libs/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -662,15 +662,6 @@ function areDatesIdentical(dateTimeStringFirst: string, dateTimeStringSecond: st
const isTimeAtLeastOneMinuteInFuture = ({timeString, dateTimeString}: {timeString?: string; dateTimeString: string}): boolean => {
let dateToCheck = dateTimeString;
if (timeString) {
// return false;
// Parse the hour and minute from the time input
const [hourStr] = timeString.split(/[:\s]+/);
const hour = parseInt(hourStr, 10);

if (hour === 0) {
return false;
}

dateToCheck = combineDateAndTime(timeString, dateTimeString);
}

Expand Down

0 comments on commit f9b05c0

Please sign in to comment.