Catch invalid dates
This commit is contained in:
parent
4255d7ce44
commit
1e340060ec
2 changed files with 6 additions and 3 deletions
1
packages/graphics-components/.gitignore
vendored
1
packages/graphics-components/.gitignore
vendored
|
|
@ -192,3 +192,4 @@ dist
|
|||
# End of https://www.toptal.com/developers/gitignore/api/node,macos,linux
|
||||
|
||||
*storybook.log
|
||||
storybook-static/
|
||||
|
|
|
|||
|
|
@ -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];
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue