Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/lib/isISO8601.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ const isValidDate = (str) => {
// this check is meant to catch invalid dates
// like 2009-02-31
// first check for ordinal dates
const ordinalMatch = str.match(/^(\d{4})-?(\d{3})([ T]{1}\.*|$)/);
const ordinalMatch = str.match(/^([+-]?)(\d{4})-?(\d{3})([ T]{1}\.*|$)/);
if (ordinalMatch) {
const oYear = Number(ordinalMatch[1]);
const oDay = Number(ordinalMatch[2]);
const oYear = Number(ordinalMatch[2]);
const oDay = Number(ordinalMatch[3]);
// if is leap year
if ((oYear % 4 === 0 && oYear % 100 !== 0) || oYear % 400 === 0) return oDay <= 366;
return oDay <= 365;
Expand Down
16 changes: 16 additions & 0 deletions test/validators.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12453,6 +12453,22 @@ describe('Validators', () => {
});
});

it('should validate ISO 8601 dates, validating signed ordinal dates in strict mode', () => {
test({
validator: 'isISO8601',
args: [
{ strict: true },
],
valid: [
'+2009-145',
'+2020-366',
],
invalid: [
'+2009-366',
],
});
});

it('should validate ISO 8601 dates, with strictSeparator = true', () => {
test({
validator: 'isISO8601',
Expand Down
Loading