diff --git a/moment.js b/moment.js index aa2e5c4e41..fe57173116 100644 --- a/moment.js +++ b/moment.js @@ -2126,6 +2126,8 @@ return toInt(input) + (toInt(input) > 68 ? 1900 : 2000); }; + moment.isDate = isDate; + /************************************ Moment Prototype ************************************/ diff --git a/test/moment/is_date.js b/test/moment/is_date.js new file mode 100644 index 0000000000..455a395b4f --- /dev/null +++ b/test/moment/is_date.js @@ -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(); + } +};