Catch invalid dates

This commit is contained in:
wires 2026-03-27 21:07:20 -04:00
parent 4255d7ce44
commit 1e340060ec
2 changed files with 6 additions and 3 deletions

View file

@ -192,3 +192,4 @@ dist
# End of https://www.toptal.com/developers/gitignore/api/node,macos,linux
*storybook.log
storybook-static/

View file

@ -1,7 +1,9 @@
/**
* Converts a date string to a short date format.
* @param d - The date string to be converted.
* @returns The short date format string.
* @returns The short date format string, or empty string if missing or invalid (avoids throwing on `new Date('').toISOString()`).
*/
export const getShortDate = (d: string) =>
new Date(d).toISOString().split('T')[0];
export const getShortDate = (d: string) => {
if (!d || Number.isNaN(Date.parse(d))) return '';
return new Date(d).toISOString().split('T')[0];
};