show error for invalid dates

it srsly messes with binary search!
This commit is contained in:
Lachlan Kermode
2020-06-26 12:57:51 +02:00
parent 4c04e2cf95
commit cdd88917d4

View File

@@ -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
}