mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-11 19:37: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 boolTag:
|
||||||
case dateTag:
|
case dateTag:
|
||||||
// Coerce dates and booleans to numbers, dates to milliseconds and
|
case numberTag:
|
||||||
// booleans to `1` or `0` treating invalid dates coerced to `NaN` as
|
// Coerce booleans to `1` or `0` and dates to milliseconds.
|
||||||
// not equal.
|
// Invalid dates are coerced to `NaN`.
|
||||||
return +object == +other;
|
return eq(+object, +other);
|
||||||
|
|
||||||
case errorTag:
|
case errorTag:
|
||||||
return object.name == other.name && object.message == other.message;
|
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 regexpTag:
|
||||||
case stringTag:
|
case stringTag:
|
||||||
// Coerce regexes to strings and treat strings, primitives and objects,
|
// Coerce regexes to strings and treat strings, primitives and objects,
|
||||||
|
|||||||
@@ -9777,9 +9777,10 @@
|
|||||||
var date = new Date(2012, 4, 23);
|
var date = new Date(2012, 4, 23);
|
||||||
|
|
||||||
assert.strictEqual(_.isEqual(date, new Date(2012, 4, 23)), true);
|
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, new Date(2013, 3, 25)), false);
|
||||||
assert.strictEqual(_.isEqual(date, { 'getTime': lodashStable.constant(+date) }), 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) {
|
QUnit.test('should compare error objects', function(assert) {
|
||||||
|
|||||||
@@ -285,6 +285,7 @@
|
|||||||
'Commutative equality is implemented for `0` and `-0`',
|
'Commutative equality is implemented for `0` and `-0`',
|
||||||
'`new Number(0)` and `-0` are not equal',
|
'`new Number(0)` and `-0` are not equal',
|
||||||
'Commutative equality is implemented for `new Number(0)` and `-0`',
|
'Commutative equality is implemented for `new Number(0)` and `-0`',
|
||||||
|
'Invalid dates are not equal',
|
||||||
'false'
|
'false'
|
||||||
],
|
],
|
||||||
'isFinite': [
|
'isFinite': [
|
||||||
|
|||||||
Reference in New Issue
Block a user