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: [DHIS2-18116] check return value of parseDate #3823

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Changes from all 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
17 changes: 12 additions & 5 deletions src/core_modules/capture-core/converters/formToClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,35 @@ 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();
}

function convertDate(dateValue: string) {
const parsedDate = parseDate(dateValue);
// $FlowFixMe[incompatible-use] automated comment
return parseDate(dateValue).momentDate.toISOString();
return parsedDate.isValid ? parsedDate.momentDate.toISOString() : null;
}

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
Loading