diff --git a/src/shared/utils/helpers/format-past-date.ts b/src/shared/utils/helpers/format-past-date.ts index 5bef4e83..1e0ffda8 100644 --- a/src/shared/utils/helpers/format-past-date.ts +++ b/src/shared/utils/helpers/format-past-date.ts @@ -2,8 +2,23 @@ import formatDistanceStrict from "date-fns/formatDistanceStrict"; import parseISO from "date-fns/parseISO"; export default function (dateString?: string) { - const parsed = parseISO((dateString ?? Date.now().toString()) + "Z"); - return formatDistanceStrict(parsed, new Date(), { - addSuffix: true, - }); + if (!dateString) { + console.error(err); + return "DATE ERROR"; + } + + try { + const parsed = parseISO(Date.now().toString() + "Z"); + return formatDistanceStrict(parsed, new Date(), { + addSuffix: true, + }); + } catch (err) { + console.error(err); + if (err instanceof RangeError) { + console.error( + `Got the invalid value of ${dateString} when attempting to parse to ISO date`, + ); + return "DATE ERROR"; + } + } }