diff --git a/lodash.js b/lodash.js index 8da0d7ed6..2ceb971bd 100644 --- a/lodash.js +++ b/lodash.js @@ -5168,18 +5168,14 @@ case boolTag: case dateTag: - // Coerce dates and booleans to numbers, dates to milliseconds and - // booleans to `1` or `0` treating invalid dates coerced to `NaN` as - // not equal. - return +object == +other; + case numberTag: + // Coerce booleans to `1` or `0` and dates to milliseconds. + // Invalid dates are coerced to `NaN`. + return eq(+object, +other); case errorTag: return object.name == other.name && object.message == other.message; - case numberTag: - // Treat `NaN` vs. `NaN` as equal. - return (object != +object) ? other != +other : object == +other; - case regexpTag: case stringTag: // Coerce regexes to strings and treat strings, primitives and objects, diff --git a/test/test.js b/test/test.js index b979b622e..666c1a353 100644 --- a/test/test.js +++ b/test/test.js @@ -9777,9 +9777,10 @@ var date = new Date(2012, 4, 23); assert.strictEqual(_.isEqual(date, new Date(2012, 4, 23)), true); + assert.strictEqual(_.isEqual(new Date('a'), new Date('b')), true); + assert.strictEqual(_.isEqual(date, new Date(2013, 3, 25)), false); assert.strictEqual(_.isEqual(date, { 'getTime': lodashStable.constant(+date) }), false); - assert.strictEqual(_.isEqual(new Date('a'), new Date('a')), false); }); QUnit.test('should compare error objects', function(assert) { diff --git a/test/underscore.html b/test/underscore.html index a3e56e819..e7b231076 100644 --- a/test/underscore.html +++ b/test/underscore.html @@ -285,6 +285,7 @@ 'Commutative equality is implemented for `0` and `-0`', '`new Number(0)` and `-0` are not equal', 'Commutative equality is implemented for `new Number(0)` and `-0`', + 'Invalid dates are not equal', 'false' ], 'isFinite': [