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
12 changes: 12 additions & 0 deletions lib/types/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,18 @@ internals.isoDate = function (value) {
return null;
}

const day = Number(value.split('T')[0].replace(/^-?/, '').split('-')[2]);

if (/T24:00$/.test(value)) {
const nextDate = new Date(value.replace(/T24:00/, '')).setDate(day + 1);
if (date.getTime() !== nextDate) {
return null;
}
}
else if (day !== date.getDate()) {
return null;
}

return date.toISOString();
};

Expand Down
20 changes: 19 additions & 1 deletion test/types/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -5399,7 +5399,7 @@ describe('string', () => {
});
});

describe('isoData()', () => {
describe('isoDate()', () => {

it('validates isoDate', () => {

Expand Down Expand Up @@ -5574,6 +5574,24 @@ describe('string', () => {
path: [],
type: 'string.isoDate',
context: { value: '2013-1841', label: 'value' }
}],
['2013-04-31', false, {
message: '"value" must be in iso format',
path: [],
type: 'string.isoDate',
context: { value: '2013-04-31', label: 'value' }
}],
['2013-04-31T24:00', false, {
message: '"value" must be in iso format',
path: [],
type: 'string.isoDate',
context: { value: '2013-04-31T24:00', label: 'value' }
}],
['2025-02-29T12:21', false, {
message: '"value" must be in iso format',
path: [],
type: 'string.isoDate',
context: { value: '2025-02-29T12:21', label: 'value' }
}]
]);
});
Expand Down