diff --git a/lib/types/string.js b/lib/types/string.js index ba5650ef..0e99b8c9 100755 --- a/lib/types/string.js +++ b/lib/types/string.js @@ -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(); }; diff --git a/test/types/string.js b/test/types/string.js index a02a2d2a..b57a1171 100755 --- a/test/types/string.js +++ b/test/types/string.js @@ -5399,7 +5399,7 @@ describe('string', () => { }); }); - describe('isoData()', () => { + describe('isoDate()', () => { it('validates isoDate', () => { @@ -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' } }] ]); });