diff --git a/src/reducers/validate/validators.js b/src/reducers/validate/validators.js index b3bce16..d7db98d 100644 --- a/src/reducers/validate/validators.js +++ b/src/reducers/validate/validators.js @@ -21,6 +21,10 @@ function makeError (type, id, message) { } } +function isValidDate (d) { + return d instanceof Date && !isNaN(d) +} + const isLeaf = node => (Object.keys(node.children).length === 0) const isDuplicate = (node, set) => { return (set.has(node.key)) } @@ -136,18 +140,6 @@ export function validateDomain (domain) { }) ) - // Message the number of failed items in domain - Object.keys(discardedDomain).forEach(disc => { - const len = discardedDomain[disc].length - if (len) { - sanitizedDomain.notifications.push({ - message: `${len} invalid ${disc} not displayed.`, - items: discardedDomain[disc], - type: 'error' - }) - } - }) - // Validate uniqueness of filters const filterSet = new Set([]) const duplicateFilters = [] @@ -167,9 +159,24 @@ export function validateDomain (domain) { sanitizedDomain.events.forEach((event, idx) => { event.id = idx event.datetime = calcDatetime(event.date, event.time) + if (!isValidDate(event.datetime)) { + discardedDomain['events'].push({ ...event, error: makeError('events', event.id, `Invalid date. This will break timemap! Please fix.`) }) + } }) sanitizedDomain.events.sort((a, b) => a.datetime - b.datetime) + // Message the number of failed items in domain + Object.keys(discardedDomain).forEach(disc => { + const len = discardedDomain[disc].length + if (len) { + sanitizedDomain.notifications.push({ + message: `${len} invalid ${disc} not displayed.`, + items: discardedDomain[disc], + type: 'error' + }) + } + }) + return sanitizedDomain }