From b5213670ed4d97b9226d3ff7760b9218fa62b1d9 Mon Sep 17 00:00:00 2001 From: Aiden Keating Date: Mon, 15 Apr 2019 13:21:25 +0100 Subject: [PATCH] INTLY-1362 Validate walkthrough date field before displaying --- .../walkthroughDetails/walkthroughDetails.js | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/components/walkthroughDetails/walkthroughDetails.js b/src/components/walkthroughDetails/walkthroughDetails.js index 99f661375..1f13552ca 100644 --- a/src/components/walkthroughDetails/walkthroughDetails.js +++ b/src/components/walkthroughDetails/walkthroughDetails.js @@ -10,8 +10,18 @@ class WalkthroughDetails extends React.Component { this.state = {}; } + static validWalkthroughDate(dateString) { + try { + // We need to modify the returned string to allow for Firefox compatibility. This just keeps the date section, removes the time and everything after. + return new Date(dateString.split(' ')[0]).toISOString().slice(0, 10); + } catch (e) { + return null; + } + } + render() { const { walkthroughInfo } = this.props; + return ( @@ -22,7 +32,8 @@ class WalkthroughDetails extends React.Component {
Source:
- {walkthroughInfo.type === 'path' ? ( + {walkthroughInfo.type === 'path' || + !WalkthroughDetails.validWalkthroughDate(walkthroughInfo.commitDate) ? (
---
) : (
@@ -39,7 +50,7 @@ class WalkthroughDetails extends React.Component { {walkthroughInfo.type === 'path' ? (
---
) : ( -
{new Date(walkthroughInfo.commitDate).toISOString().slice(0, 10)}
+
{WalkthroughDetails.validWalkthroughDate(walkthroughInfo.commitDate)}
)}