Skip to content

Commit

Permalink
Merge pull request #961 from CruGlobal/blank-page-on-bad-data
Browse files Browse the repository at this point in the history
Helpscout - Fixing blank screen error on contact details
  • Loading branch information
dr-bizz authored Jun 19, 2024
2 parents deafe90 + 64f3bd9 commit f58d594
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/lib/intlFormat.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,14 @@ describe('intlFormat', () => {

expect(date).toBeNull();
});

it('returns if month is null', () => {
const date = dateFromParts(0, 0, 2000, locale);

expect(date).toBe(
'Invalid Date - you specified 0 (of type number) as a month, which is invalid',
);
});
});
//this test often fails locally. It passes on github.
describe('dateTimeFormat', () => {
Expand Down
10 changes: 9 additions & 1 deletion src/lib/intlFormat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,16 @@ export const dateFromParts = (
}

if (typeof year === 'number') {
return dateFormat(DateTime.local(year, month, day), locale);
const date = DateTime.local(year, month, day);
if (date.invalidReason || date.invalidExplanation) {
return `Invalid Date - ${date.invalidExplanation}`;
}
return dateFormat(date, locale);
} else {
const date = DateTime.local().set({ month, day });
if (date.invalidReason || date.invalidExplanation) {
return `Invalid Date - ${date.invalidExplanation}`;
}
return dayMonthFormat(day, month, locale);
}
};
Expand Down

0 comments on commit f58d594

Please sign in to comment.