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) O3-2489 - toDateObjectStrict returns null if the passed string is not considered a valid date #963

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open
3 changes: 2 additions & 1 deletion packages/framework/esm-utils/src/omrs-dates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ export function isOmrsDateToday(date: DateInput) {
*/
export function toDateObjectStrict(omrsDateString: string): Date | null {
if (!isOmrsDateStrict(omrsDateString)) {
return null;
// return null;
throw new Error(`The date "${omrsDateString}" is not valid. This is a custom error to prevent null dates from being written in the database.`);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// return null;
throw new Error(`The date "${omrsDateString}" is not valid. This is a custom error to prevent null dates from being written in the database.`);
throw new Error("`toDateObjectStrict` failed to parse date string "${omrsDateString}".`);

}

return dayjs(omrsDateString, isoFormat).toDate();
Expand Down