you-dont-need / You-Dont-Need-Momentjs

List of functions which you can use to replace moment.js + ESLint Plugin
MIT License
13.27k stars 318 forks source link

fix same #63

Closed cymen closed 5 years ago

cymen commented 5 years ago

Native under Is Same is wrong:

// Native
new Date(2010, 9, 20) === new Date(2010, 9, 21);
// => false
new Date(2010, 9, 20) === new Date(2010, 9, 20);
// => true

To compare native JavaScript dates one needs to use .getTime() or .valueOf(). The first entry above happens to be false but that is due to object equality. The other lines don't return the above result on a couple of JavaScript engines:

node v8.14.0:

> new Date(2010, 9, 20) === new Date(2010, 9, 20);
false

Chrome 70.0.3538.110:

new Date(2010, 9, 20) === new Date(2010, 9, 20);
false

Firefox 64.0:

new Date(2010, 9, 20) === new Date(2010, 9, 20);
false

I've added the missing tests for this too along with examples of using .valueOf(), .getTime() or even a mix of .valueOf() and .getTime() to compare date equality.

coveralls commented 5 years ago

Pull Request Test Coverage Report for Build 165


Totals Coverage Status
Change from base Build 164: 0.0%
Covered Lines: 43
Relevant Lines: 43

💛 - Coveralls