diff --git a/src/dateparser/dateparser.js b/src/dateparser/dateparser.js index 9d98bff2b7..695e87de29 100644 --- a/src/dateparser/dateparser.js +++ b/src/dateparser/dateparser.js @@ -113,6 +113,10 @@ angular.module('ui.bootstrap.dateparser', []) // Check if date is valid for specific month (and year for February). // Month: 0 = Jan, 1 = Feb, etc function isValid(year, month, date) { + if (date < 1) { + return false; + } + if ( month === 1 && date > 28) { return date === 29 && ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0); } diff --git a/src/dateparser/test/dateparser.spec.js b/src/dateparser/test/dateparser.spec.js index 8bf233f241..331361b5a7 100644 --- a/src/dateparser/test/dateparser.spec.js +++ b/src/dateparser/test/dateparser.spec.js @@ -84,6 +84,10 @@ describe('date parser', function () { expect(dateParser.parse('29.02.2013', 'dd.MM.yyyy')).toBeUndefined(); }); + it('should not work for 0 number of days', function() { + expect(dateParser.parse('00.02.2013', 'dd.MM.yyyy')).toBeUndefined(); + }); + it('should work for 29 days in February for leap years', function() { expectParse('29.02.2000', 'dd.MM.yyyy', new Date(2000, 1, 29, 0)); });