Skip to content

Commit

Permalink
fix: validation of Time and DateTime fields in TE registration page
Browse files Browse the repository at this point in the history
  • Loading branch information
superskip committed Oct 3, 2024
1 parent 2402f1b commit ea58565
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/core_modules/capture-core/converters/formToClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,20 @@ type RangeValue = {
to: string,
}

function convertDateTime(formValue: DateTimeValue): string {
function convertDateTime(formValue: DateTimeValue): ?string {
const editedDate = formValue.date;
const editedTime = formValue.time;

const momentTime = parseTime(editedTime).momentTime;
const parsedTime = parseTime(editedTime);
if (!parsedTime.isValid) return null;
const momentTime = parsedTime.momentTime;
const hours = momentTime.hour();
const minutes = momentTime.minute();

const parsedDate = parseDate(editedDate);
if (!parsedDate.isValid) return null;
// $FlowFixMe[incompatible-type] automated comment
const momentDateTime: moment$Moment = parseDate(editedDate).momentDate;
const momentDateTime: moment$Moment = parsedDate.momentDate;
momentDateTime.hour(hours);
momentDateTime.minute(minutes);
return momentDateTime.toISOString();
Expand All @@ -36,7 +40,9 @@ function convertDate(dateValue: string) {
}

function convertTime(timeValue: string) {
const momentTime = parseTime(timeValue).momentTime;
const parsedTime = parseTime(timeValue);
if (!parsedTime.isValid) return null;
const momentTime = parsedTime.momentTime;
momentTime.locale('en');
return momentTime.format('HH:mm');
}
Expand Down

0 comments on commit ea58565

Please sign in to comment.