diff --git a/src/lib/isISO8601.js b/src/lib/isISO8601.js index 6eea9ae27..00d468efc 100644 --- a/src/lib/isISO8601.js +++ b/src/lib/isISO8601.js @@ -2,9 +2,9 @@ import assertString from './util/assertString'; /* eslint-disable max-len */ // from http://goo.gl/0ejHHW -const iso8601 = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W(0[1-9]|[1-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[0-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/; +const iso8601 = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W(0[1-9]|[1-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[0-6])))([T\s]((([01]\d|2[0-3]|24(?=:?00)(?!:?00:?(?:0[1-9]|[1-5]\d)))((:?)[0-5]\d)?)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/; // same as above, except with a strict 'T' separator between date and time -const iso8601StrictSeparator = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W(0[1-9]|[1-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[0-6])))([T]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/; +const iso8601StrictSeparator = /^([\+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W(0[1-9]|[1-4]\d|5[0-3])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[0-6])))([T]((([01]\d|2[0-3]|24(?=:?00)(?!:?00:?(?:0[1-9]|[1-5]\d)))((:?)[0-5]\d)?)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|([\+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/; /* eslint-enable max-len */ const isValidDate = (str) => { // str must have passed the ISO8601 check diff --git a/test/validators.test.js b/test/validators.test.js index 98d2a12ff..258d3ca96 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -12362,6 +12362,8 @@ describe('Validators', () => { '20090621T0545Z', '2007-04-06T00:00', '2007-04-05T24:00', + '2007-04-05T24:00:00', + '20070405T240000', '2010-02-18T16:23:48.5', '2010-02-18T16:23:48,444', '2010-02-18T16:23:48,3-06:00', @@ -12383,6 +12385,10 @@ describe('Validators', () => { '2009367', '2009-', '2007-04-05T24:50', + '2007-04-05T24:00:30', + '20070405T240030', + '2007-04-05T2400:30', + '2007-04-05T24:0030', '2009-000', '2009-M511', '2009M511', @@ -12483,6 +12489,8 @@ describe('Validators', () => { '20090621T0545Z', '2007-04-06T00:00', '2007-04-05T24:00', + '2007-04-05T24:00:00', + '20070405T240000', '2010-02-18T16:23:48.5', '2010-02-18T16:23:48,444', '2010-02-18T16:23:48,3-06:00', @@ -12500,6 +12508,10 @@ describe('Validators', () => { '2009367', '2009-', '2007-04-05T24:50', + '2007-04-05T24:00:30', + '20070405T240030', + '2007-04-05T2400:30', + '2007-04-05T24:0030', '2009-000', '2009-M511', '2009M511',