Skip to content

Commit

Permalink
Merge pull request #223 from cidgoh/date-min-max
Browse files Browse the repository at this point in the history
added testDateRange
  • Loading branch information
ddooley authored Oct 12, 2021
2 parents ebb1b72 + cb451dc commit c717cff
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions script/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,9 @@ const getInvalidCells = (hot, data) => {
case 'xs:date':
// moment is a date format addon
valid = moment(cellVal, 'YYYY-MM-DD', true).isValid();
if (valid) {
valid = testDateRange(cellVal, fields[col]);
}
break;
case 'select':
valid = validateValAgainstVocab(cellVal, fields[col].flatVocabulary);
Expand Down Expand Up @@ -1203,6 +1206,27 @@ const testNumericRange = (number, field) => {
}
return true
}

/**
* Test a given date against an upper or lower range, if any.
* @param {Date} date to be compared.
* @param {Object} field that contains min and max limits.
* @return {Boolean} validity of field.
*/
const testDateRange = (aDate, field) => {

if (field['xs:minInclusive'] !== '') {
if (aDate < field['xs:minInclusive']) {
return false
}
}
if (field['xs:maxInclusive'] !== '') {
if (aDate > field['xs:maxInclusive'])
return false
}
return true
}

/**
* Validate a value against an array of source values.
* @param {String} val Cell value.
Expand Down

0 comments on commit c717cff

Please sign in to comment.