Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #435: Convert returned comparison in isBefore() to a boolean. #436

Merged
merged 1 commit into from
Sep 18, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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