From 3cbe42e1baa5688ac3c012a1f4943eb26803edb4 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Fri, 2 Aug 2019 11:10:25 +0200 Subject: [PATCH] Fixed ordinal checker crashing edit story form. --- .../components/edit-story-modal/component.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/marko/page/story-content/components/edit-story-modal/component.js b/marko/page/story-content/components/edit-story-modal/component.js index 5afce46..99e577b 100644 --- a/marko/page/story-content/components/edit-story-modal/component.js +++ b/marko/page/story-content/components/edit-story-modal/component.js @@ -2,6 +2,8 @@ const moment = require("moment") const {storyApi} = require("../../../../../rpdata/api/Story") +const ORDINAL_REGEX = /[0-9]{1,2}(st|nd|rd|th)/g + module.exports = class { onCreate() { this.state = { @@ -45,11 +47,13 @@ module.exports = class { const values = this.state.values let fictionalDate = new Date(values.fictionalDate + " UTC") - if (values.fictionalDate != "") { + if (values.fictionalDate) { if (Number.isNaN(fictionalDate.getTime())) { this.state.error = `Could not parse ${values.fictionalDate} as date.` - if (values.fictionalDate.includes("th")) { - this.state.error += " Try to remove the 'th'." + + const ordinal = values.fictionalDate.match(ORDINAL_REGEX)[0] + if (ordinal != null) { + this.state.error += " Try to remove the '"+ordinal.slice(-2)+"'." } return