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

Commit

Permalink
fix(dateparser): add extra validation constraint to days
Browse files Browse the repository at this point in the history
day equal to 0 is not allowed
  • Loading branch information
Sylwester Grabowski authored and wesleycho committed Mar 24, 2015
1 parent b5e534b commit c19b887
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/dateparser/dateparser.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions src/dateparser/test/dateparser.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
});
Expand Down

0 comments on commit c19b887

Please sign in to comment.