Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

shallowEqual on Date objects gives false positives #264

Open
reu opened this issue Aug 24, 2017 · 2 comments
Open

shallowEqual on Date objects gives false positives #264

reu opened this issue Aug 24, 2017 · 2 comments

Comments

@reu
Copy link

reu commented Aug 24, 2017

I can't say if this is the intended behavior, but we can't use shallowEqual to compare Date objects:

d1 = new Date(Date.UTC(2010, 10, 10)) // 2010-11-10T00:00:00.000Z
d2 = new Date(Date.UTC(2010, 10, 11)) // 2010-11-11T00:00:00.000Z
shallowEqual(d1, d2) // true

This happens because Object.keys(new Date) returns an empty list, which skips the checks of each object property here: https://github.com/facebook/fbjs/blob/master/packages/fbjs/src/core/shallowEqual.js#L59

So, should we also return false when the object returns no keys?

@erickzanardo
Copy link

👍

@osdnk
Copy link

osdnk commented Jan 12, 2019

@reu
AFAIK it's good and expected behaviour to return true. Date is quite a special object in JS and has no normal fields since it's supported natively (take a look e.g. for JSC https://github.com/WebKit/webkit/blob/89c28d471fae35f1788a0f857067896a10af8974/Source/JavaScriptCore/runtime/DatePrototype.cpp).

So it's absolutely fine to tell that these objects are shallowly equal. I think I might be very bad idea to return false, because then in a case of the same dates it will return false as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants