diff --git a/src/formio/validators/MinMaxTimeValidator.js b/src/formio/validators/MinMaxTimeValidator.js index a8ca96775..76ba2e2f1 100644 --- a/src/formio/validators/MinMaxTimeValidator.js +++ b/src/formio/validators/MinMaxTimeValidator.js @@ -14,12 +14,12 @@ const validateTimeBoundaries = (minBoundary, maxBoundary, timeValue) => { // Case 1: only one boundary is given if (!minTime || !maxTime) { if (minTime) return {isValid: parsedValue >= minTime, errorKeys: ['minTime']}; - if (maxTime) return {isValid: parsedValue < maxTime, errorKeys: ['maxTime']}; + if (maxTime) return {isValid: parsedValue <= maxTime, errorKeys: ['maxTime']}; } else { // Case 2: min boundary is smaller than max boundary if (minTime < maxTime) { const isTooEarly = parsedValue < minTime; - const isTooLate = parsedValue >= maxTime; + const isTooLate = parsedValue > maxTime; return { isValid: !isTooEarly && !isTooLate, errorKeys: [isTooEarly ? 'minTime' : 'maxTime', 'invalid_time'], @@ -27,7 +27,7 @@ const validateTimeBoundaries = (minBoundary, maxBoundary, timeValue) => { } else { // Case 3: min boundary is bigger than max boundary (it's the next day. For example min = 08:00, max = 01:00) return { - isValid: !(parsedValue >= maxTime && parsedValue < minTime), + isValid: !(parsedValue > maxTime && parsedValue < minTime), // Basically, the opposite of 01:00 < `parsedValue` < 08:00 errorKeys: ['invalid_time'], }; } diff --git a/src/jstests/formio/components/time.spec.js b/src/jstests/formio/components/time.spec.js index 0c494b300..02101c97d 100644 --- a/src/jstests/formio/components/time.spec.js +++ b/src/jstests/formio/components/time.spec.js @@ -15,9 +15,9 @@ describe('Time Component', () => { formJSON.components[0].validate.minTime = '09:00:00'; formJSON.components[0].validate.maxTime = '17:00:00'; - const validValues = ['09:00:00', '10:30:00', '11:11:11']; + const validValues = ['09:00:00', '10:30:00', '11:11:11', '17:00:00']; - const invalidValues = ['17:00:00', '17:30:00', '08:30:00']; + const invalidValues = ['17:30:00', '08:30:00']; const testValidity = (values, valid) => { values.forEach(value => { @@ -125,7 +125,7 @@ describe('Time Component', () => { let formJSON = _.cloneDeep(timeForm); formJSON.components[0].validate.maxTime = '09:00:00'; - const validValues = ['08:00:00']; + const validValues = ['08:00:00', '09:00:00']; const invalidValues = ['17:00:00']; @@ -165,7 +165,7 @@ describe('Time Component', () => { formJSON.components[0].validate.maxTime = '01:00:00'; formJSON.components[0].validate.minTime = '08:00:00'; - const validValues = ['09:00:00', '00:30:00']; + const validValues = ['09:00:00', '00:30:00', '01:00:00', '08:00:00']; const invalidValues = ['02:00:00'];