Skip to content

Commit 8a109e7

Browse files
KamalAmanmattphillips
authored andcommitted
Fixes bug with difference dates in the same second returning true (#12)
1 parent 49e6acf commit 8a109e7

File tree

4 files changed

+4
-2
lines changed

4 files changed

+4
-2
lines changed

src/diff/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ const diff = (lhs, rhs) => {
1313
}, {});
1414

1515
if (isDate(l) || isDate(r)) {
16-
if (l.toString() == r.toString()) return {};
16+
if (l.valueOf() == r.valueOf()) return {};
1717
return r;
1818
}
1919

src/diff/index.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('.diff', () => {
3535
[100, () => ({})],
3636
[() => ({}), 100],
3737
[new Date('2017-01-01'), new Date('2017-01-02')],
38+
[new Date('2017-01-01T00:00:00.636Z'), new Date('2017-01-01T00:00:00.637Z')],
3839
]).test('returns right hand side value when different to left hand side value (%s, %s)', (lhs, rhs) => {
3940
expect(diff(lhs, rhs)).toEqual(rhs);
4041
});

src/updated/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const updatedDiff = (lhs, rhs) => {
1010
const r = properObject(rhs);
1111

1212
if (isDate(l) || isDate(r)) {
13-
if (l.toString() == r.toString()) return {};
13+
if (l.valueOf() == r.valueOf()) return {};
1414
return r;
1515
}
1616

src/updated/index.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ describe('.updatedDiff', () => {
3535
[100, () => ({})],
3636
[() => ({}), 100],
3737
[new Date('2017-01-01'), new Date('2017-01-02')],
38+
[new Date('2017-01-01T00:00:00.636Z'), new Date('2017-01-01T00:00:00.637Z')],
3839
]).test('returns right hand side value when different to left hand side value (%s, %s)', (lhs, rhs) => {
3940
expect(updatedDiff(lhs, rhs)).toEqual(rhs);
4041
});

0 commit comments

Comments
 (0)