diff --git a/package.json b/package.json index 69fb91f..4c86ca0 100644 --- a/package.json +++ b/package.json @@ -65,7 +65,7 @@ "clean": "rimraf build", "build": "craco build", "optimise": "gzip -kr build/static", - "full-build": "npm run clean; NODE_ENV=production GENERATE_SOURCEMAP=false npm run build; npm run optimise", + "full-build": "npm run clean; NODE_ENV=production npm run build; npm run optimise", "analyze-build": "FORCE_ANALYZE=true npm run build", "test": "craco test" }, diff --git a/src/components/DateTime.tsx b/src/components/DateTime.tsx index 7115e93..85ca12d 100644 --- a/src/components/DateTime.tsx +++ b/src/components/DateTime.tsx @@ -13,6 +13,9 @@ import "./DateTime.less"; +import Debug from "debug"; +const debug = Debug("kristweb:date-time"); + interface OwnProps { date?: Date | string | null; timeAgo?: boolean; @@ -40,9 +43,20 @@ const showRelativeDates = useBooleanSetting("showRelativeDates"); if (!date) return null; - const realDate = typeof date === "string" ? new Date(date) : date; - const relative = Date.now() - realDate.getTime(); + // Attempt to convert the date, failing safely + let realDate: Date; + try { + realDate = typeof date === "string" ? new Date(date) : date; + // Some browsers don't throw until the date is actually used + realDate.toISOString(); + } catch (err) { + debug("error parsing date %s", date); + console.error(err); + return <>INVALID DATE; + } + + const relative = Date.now() - realDate.getTime(); const isTimeAgo = timeAgo || (showRelativeDates && !neverRelative && relative < RELATIVE_DATE_THRESHOLD); const classes = classNames("date-time", props.className, { diff --git a/src/pages/dev/DevPage.tsx b/src/pages/dev/DevPage.tsx index 390b62c..6858640 100644 --- a/src/pages/dev/DevPage.tsx +++ b/src/pages/dev/DevPage.tsx @@ -8,6 +8,7 @@ import { ImportBackupModal } from "../backup/ImportBackupModal"; import { SendTransactionModal } from "../transactions/send/SendTransactionModal"; import { AuthorisedAction } from "@comp/auth/AuthorisedAction"; +import { DateTime } from "@comp/DateTime"; import { useWallets, deleteWallet } from "@wallets";