Fixed ordinal checker crashing edit story form.
the build was successful

This commit is contained in:
2019-08-02 11:10:25 +02:00
parent 01b501f9e5
commit 3cbe42e1ba
@@ -2,6 +2,8 @@ const moment = require("moment")
const {storyApi} = require("../../../../../rpdata/api/Story") const {storyApi} = require("../../../../../rpdata/api/Story")
const ORDINAL_REGEX = /[0-9]{1,2}(st|nd|rd|th)/g
module.exports = class { module.exports = class {
onCreate() { onCreate() {
this.state = { this.state = {
@@ -45,11 +47,13 @@ module.exports = class {
const values = this.state.values const values = this.state.values
let fictionalDate = new Date(values.fictionalDate + " UTC") let fictionalDate = new Date(values.fictionalDate + " UTC")
if (values.fictionalDate != "") { if (values.fictionalDate) {
if (Number.isNaN(fictionalDate.getTime())) { if (Number.isNaN(fictionalDate.getTime())) {
this.state.error = `Could not parse ${values.fictionalDate} as date.` 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 return