diff --git a/src/core_modules/capture-core/converters/formToClient.js b/src/core_modules/capture-core/converters/formToClient.js index 1e8a933f36..adca6b5b72 100644 --- a/src/core_modules/capture-core/converters/formToClient.js +++ b/src/core_modules/capture-core/converters/formToClient.js @@ -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(); @@ -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'); }