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

isEmpty(new Date) returns true instead of false #5131

Closed
dellyoung opened this issue Apr 6, 2021 · 6 comments
Closed

isEmpty(new Date) returns true instead of false #5131

dellyoung opened this issue Apr 6, 2021 · 6 comments

Comments

@dellyoung
Copy link

_.isEmpty(new Date)

Actual returns:

true

Expected:

false

dellyoung pushed a commit to dellyoung/lodash that referenced this issue Apr 6, 2021
@dellyoung
Copy link
Author

dellyoung commented Apr 6, 2021

PR

@Tracer1337
Copy link

Why do you expect false here? I would consider an empty Date object as an object without a timestamp, but that does not exist (as far as I know).

@graup
Copy link

graup commented Apr 22, 2021

According to the documentation, "objects are considered empty if they have no own enumerable string keyed properties." Thus IMO true is the expected value for isEmpty(new Date) as a date is an object with no own properties.

@Tracer1337
Copy link

Considering the Object.getOwnPropertyNames methods, all Date objects are empty

> Object.getOwnPropertyNames(new Date)
[]
> Object.getOwnPropertyNames(new Date())
[]
> Object.getOwnPropertyNames(new Date("01.01.2021"))
[]

That is also counterintuitive.

@jdalton
Copy link
Member

jdalton commented Apr 23, 2021

According to the documentation, "objects are considered empty if they have no own enumerable string keyed properties." Thus IMO true is the expected value for isEmpty(new Date) as a date is an object with no own properties.

Yes. This method name has always carried with it some confusion. Instead of tweaking the method I think we should rename it. I'm open to PRs for that :)

@jdalton jdalton closed this as completed Apr 23, 2021
@dellyoung
Copy link
Author

dellyoung commented May 2, 2021

According to the documentation, "objects are considered empty if they have no own enumerable string keyed properties." Thus IMO true is the expected value for isEmpty(new Date) as a date is an object with no own properties.

Yes. This method name has always carried with it some confusion. Instead of tweaking the method I think we should rename it. I'm open to PRs for that :)

Thank you, I was misunderstood by the name, I think it needs to be renamed.

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

No branches or pull requests

4 participants