mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-01-29 06:27:49 +00:00
Make _.isEqual treat invalid dates as equiv.
This commit is contained in:
12
lodash.js
12
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,
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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': [
|
||||
|
||||
Reference in New Issue
Block a user