Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix can't update the custom time of the status to 00:59 #40853

Merged
merged 8 commits into from
Apr 25, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.pl5, styles.pr5]}
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
/>
) : (
<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
8 changes: 0 additions & 8 deletions src/libs/DateUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -663,14 +663,6 @@ const isTimeAtLeastOneMinuteInFuture = ({timeString, dateTimeString}: {timeStrin
let dateToCheck = dateTimeString;
if (timeString) {
// return false;
nkdengineer marked this conversation as resolved.
Show resolved Hide resolved
// 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
Loading