From 1e340060ec3a1a4da36d17c4f8f3c4c7f299825e Mon Sep 17 00:00:00 2001 From: wires Date: Fri, 27 Mar 2026 21:07:20 -0400 Subject: [PATCH] Catch invalid dates --- packages/graphics-components/.gitignore | 1 + .../graphics-components/src/components/BlogPost/utils.ts | 8 +++++--- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/packages/graphics-components/.gitignore b/packages/graphics-components/.gitignore index ba7f352..cd80296 100644 --- a/packages/graphics-components/.gitignore +++ b/packages/graphics-components/.gitignore @@ -192,3 +192,4 @@ dist # End of https://www.toptal.com/developers/gitignore/api/node,macos,linux *storybook.log +storybook-static/ diff --git a/packages/graphics-components/src/components/BlogPost/utils.ts b/packages/graphics-components/src/components/BlogPost/utils.ts index c9bc5d7..7934a0b 100644 --- a/packages/graphics-components/src/components/BlogPost/utils.ts +++ b/packages/graphics-components/src/components/BlogPost/utils.ts @@ -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]; +};