diff --git a/src/lib/isISO8601.js b/src/lib/isISO8601.js index 6eea9ae27..acf758000 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])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|(?:\+(?:(?:0\d|1[0-3]):?[0-5]\d|14:?00|(?:0\d|1[0-4]))|-(?:(?:0\d|1[01]):?[0-5]\d|12:?00|(?:0\d|1[0-2]))))?)?)?$/; // 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])((:?)[0-5]\d)?|24:?00)([\.,]\d+(?!:))?)?(\17[0-5]\d([\.,]\d+)?)?([zZ]|(?:\+(?:(?:0\d|1[0-3]):?[0-5]\d|14:?00|(?:0\d|1[0-4]))|-(?:(?:0\d|1[01]):?[0-5]\d|12:?00|(?:0\d|1[0-2]))))?)?)?$/; /* 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 cdde41a07..0cc9d983b 100644 --- a/test/validators.test.js +++ b/test/validators.test.js @@ -12359,6 +12359,12 @@ describe('Validators', () => { '2009-05-19 14:39:22-06:00', '2009-05-19 14:39:22+0600', '2009-05-19 14:39:22-01', + '2009-05-19 14:39:22+14:00', + '2009-05-19 14:39:22+1400', + '2009-05-19 14:39:22+14', + '2009-05-19 14:39:22-12:00', + '2009-05-19 14:39:22-1200', + '2009-05-19 14:39:22-12', '20090621T0545Z', '2007-04-06T00:00', '2007-04-05T24:00', @@ -12405,6 +12411,14 @@ describe('Validators', () => { '2010-13-1', 'nonsense2021-01-01T00:00:00Z', '2021-01-01T00:00:00Znonsense', + '2009-05-19 14:39:22+14:01', + '2009-05-19 14:39:22+15:00', + '2009-05-19 14:39:22+1500', + '2009-05-19 14:39:22+15', + '2009-05-19 14:39:22-12:01', + '2009-05-19 14:39:22-13:00', + '2009-05-19 14:39:22-1300', + '2009-05-19 14:39:22-13', '2009-W00', '2009-W00-1', '2024-W00', @@ -12477,6 +12491,12 @@ describe('Validators', () => { '2009W511', '2009-05-19', '2009-05-19T14:39Z', + '2009-05-19T14:39:22+14:00', + '2009-05-19T14:39:22+1400', + '2009-05-19T14:39:22+14', + '2009-05-19T14:39:22-12:00', + '2009-05-19T14:39:22-1200', + '2009-05-19T14:39:22-12', '2009-W21-2', '2009-W21-2T01:22', '2009-139', @@ -12520,6 +12540,14 @@ describe('Validators', () => { '2010-02-18T16:23.33.600', '2010-02-18T16,25:23:48,444', '2010-13-1', + '2009-05-19T14:39:22+14:01', + '2009-05-19T14:39:22+15:00', + '2009-05-19T14:39:22+1500', + '2009-05-19T14:39:22+15', + '2009-05-19T14:39:22-12:01', + '2009-05-19T14:39:22-13:00', + '2009-05-19T14:39:22-1300', + '2009-05-19T14:39:22-13', '2009-05-19 00:00', // Previously valid cases '2009-05-19 14',