From a591ca6152d305fde008a83c59e1c5181f337f61 Mon Sep 17 00:00:00 2001 From: Kamal Aman Date: Sat, 17 Jun 2017 10:51:52 -0400 Subject: [PATCH] Fixes bug with difference dates in the same second returning true --- src/diff/index.js | 2 +- src/diff/index.test.js | 1 + src/updated/index.js | 2 +- src/updated/index.test.js | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/diff/index.js b/src/diff/index.js index a44e255..74b961b 100644 --- a/src/diff/index.js +++ b/src/diff/index.js @@ -13,7 +13,7 @@ const diff = (lhs, rhs) => { }, {}); if (isDate(l) || isDate(r)) { - if (l.toString() == r.toString()) return {}; + if (l.valueOf() == r.valueOf()) return {}; return r; } diff --git a/src/diff/index.test.js b/src/diff/index.test.js index 47bf3a4..3d6cb67 100644 --- a/src/diff/index.test.js +++ b/src/diff/index.test.js @@ -35,6 +35,7 @@ describe('.diff', () => { [100, () => ({})], [() => ({}), 100], [new Date('2017-01-01'), new Date('2017-01-02')], + [new Date('2017-01-01T00:00:00.636Z'), new Date('2017-01-01T00:00:00.637Z')], ]).test('returns right hand side value when different to left hand side value (%s, %s)', (lhs, rhs) => { expect(diff(lhs, rhs)).toEqual(rhs); }); diff --git a/src/updated/index.js b/src/updated/index.js index 6a369f9..4b01775 100644 --- a/src/updated/index.js +++ b/src/updated/index.js @@ -10,7 +10,7 @@ const updatedDiff = (lhs, rhs) => { const r = properObject(rhs); if (isDate(l) || isDate(r)) { - if (l.toString() == r.toString()) return {}; + if (l.valueOf() == r.valueOf()) return {}; return r; } diff --git a/src/updated/index.test.js b/src/updated/index.test.js index b88b47c..c7f919e 100644 --- a/src/updated/index.test.js +++ b/src/updated/index.test.js @@ -35,6 +35,7 @@ describe('.updatedDiff', () => { [100, () => ({})], [() => ({}), 100], [new Date('2017-01-01'), new Date('2017-01-02')], + [new Date('2017-01-01T00:00:00.636Z'), new Date('2017-01-01T00:00:00.637Z')], ]).test('returns right hand side value when different to left hand side value (%s, %s)', (lhs, rhs) => { expect(updatedDiff(lhs, rhs)).toEqual(rhs); });