Skip to content
This repository was archived by the owner on May 29, 2019. It is now read-only.

Commit c19b887

Browse files
Sylwester Grabowskiwesleycho
Sylwester Grabowski
authored andcommitted
fix(dateparser): add extra validation constraint to days
day equal to 0 is not allowed
1 parent b5e534b commit c19b887

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/dateparser/dateparser.js

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ angular.module('ui.bootstrap.dateparser', [])
113113
// Check if date is valid for specific month (and year for February).
114114
// Month: 0 = Jan, 1 = Feb, etc
115115
function isValid(year, month, date) {
116+
if (date < 1) {
117+
return false;
118+
}
119+
116120
if ( month === 1 && date > 28) {
117121
return date === 29 && ((year % 4 === 0 && year % 100 !== 0) || year % 400 === 0);
118122
}

src/dateparser/test/dateparser.spec.js

+4
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ describe('date parser', function () {
8484
expect(dateParser.parse('29.02.2013', 'dd.MM.yyyy')).toBeUndefined();
8585
});
8686

87+
it('should not work for 0 number of days', function() {
88+
expect(dateParser.parse('00.02.2013', 'dd.MM.yyyy')).toBeUndefined();
89+
});
90+
8791
it('should work for 29 days in February for leap years', function() {
8892
expectParse('29.02.2000', 'dd.MM.yyyy', new Date(2000, 1, 29, 0));
8993
});

0 commit comments

Comments
 (0)