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