Skip to content

Commit

Permalink
Add moment.isDate method
Browse files Browse the repository at this point in the history
  • Loading branch information
ichernev committed Dec 24, 2014
1 parent ba181c6 commit 9b68dac
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
2 changes: 2 additions & 0 deletions moment.js
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,8 @@
return toInt(input) + (toInt(input) > 68 ? 1900 : 2000);
};

moment.isDate = isDate;

/************************************
Moment Prototype
************************************/
Expand Down
32 changes: 32 additions & 0 deletions test/moment/is_date.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
var moment = require('../../moment');

exports.add = {
setUp : function (done) {
moment.createFromInputFallback = function () {
throw new Error('input not handled by moment');
};
done();
},

'isDate recognizes Date objects' : function (test) {
test.ok(moment.isDate(new Date()), 'no args (now)');
test.ok(moment.isDate(new Date([2014, 02, 15])), 'array args');
test.ok(moment.isDate(new Date('2014-03-15')), 'string args');
test.ok(moment.isDate(new Date('does NOT look like a date')), 'invalid date');
test.done();
},

'isDate rejects non-Date objects' : function (test) {
test.ok(!moment.isDate(), 'nothing');
test.ok(!moment.isDate(undefined), 'undefined');
test.ok(!moment.isDate(null), 'string args');
test.ok(!moment.isDate(42), 'number');
test.ok(!moment.isDate('2014-03-15'), 'string');
test.ok(!moment.isDate([2014, 2, 15]), 'array');
test.ok(!moment.isDate({year: 2014, month: 2, day: 15}), 'object');
test.ok(!moment.isDate({toString: function () {
return '[object Date]';
}}), 'lying object');
test.done();
}
};

0 comments on commit 9b68dac

Please sign in to comment.