Skip to content

Commit

Permalink
Merge pull request #436 from rustybailey/fix_isBefore
Browse files Browse the repository at this point in the history
Fix #435: Convert returned comparison in isBefore() to a boolean.
  • Loading branch information
chriso committed Sep 18, 2015
2 parents b20a8db + 04d8b45 commit 3393c54
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
10 changes: 10 additions & 0 deletions test/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -876,6 +876,11 @@ describe('Validators', function () {
test({ validator: 'isAfter',
valid: [ '2100-08-04', new Date(Date.now() + 86400000) ],
invalid: [ '2010-07-02', new Date(0) ] });
test({ validator: 'isAfter', args: ['2011-08-03'],
valid: [ '2015-09-17' ],
invalid: [ 'invalid date' ] });
test({ validator: 'isAfter', args: ['invalid date'],
invalid: [ 'invalid date', '2015-09-17' ] });
});

it('should validate dates against an end date', function () {
Expand All @@ -888,6 +893,11 @@ describe('Validators', function () {
test({ validator: 'isBefore',
valid: [ '2000-08-04', new Date(0), new Date(Date.now() - 86400000) ],
invalid: [ '2100-07-02', new Date(2017, 10, 10) ] });
test({ validator: 'isBefore', args: ['2011-08-03'],
valid: [ '1999-12-31' ],
invalid: [ 'invalid date' ] });
test({ validator: 'isBefore', args: ['invalid date'],
invalid: [ 'invalid date', '1999-12-31' ] });
});

it('should validate that integer strings are divisible by a number', function () {
Expand Down
2 changes: 1 addition & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@
validator.isBefore = function (str, date) {
var comparison = validator.toDate(date || new Date())
, original = validator.toDate(str);
return original && comparison && original < comparison;
return !!(original && comparison && original < comparison);
};

validator.isIn = function (str, options) {
Expand Down

0 comments on commit 3393c54

Please sign in to comment.