Skip to content
New issue

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

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

Already on GitHub? # to your account

Dayjs.min behavior with single argument #2759

Open
joyhchen opened this issue Oct 28, 2024 · 0 comments
Open

Dayjs.min behavior with single argument #2759

joyhchen opened this issue Oct 28, 2024 · 0 comments

Comments

@joyhchen
Copy link

joyhchen commented Oct 28, 2024

Describe the bug

Take this example to illustrate why I might end up calling with a single arg:

const list = myApiResponse.data;
const minCreatedDate = dayjs.min(dayjs.utc(createdDate), ...list.map((item) => item.createdDate))

When list is empty, dayjs.min returns null.

However, if you instead pass these args as a list to dayjs, we get the expected result:

const minCreatedDate = dayjs.min([
     dayjs.utc(createdDate),
    ...list.map((item) => item.createdDate
])

^ this returns the createdDate as expected

Expected behavior

When dayjs.min() is passed a single argument, it should still return a result if the argument is a valid date.

Information

  • Day.js Version: 1.11.3
  • OS: Mac OS
  • Browser: Chrome
  • Time zone: UTC
@joyhchen joyhchen changed the title Dayjs.min behavior with multiple arguments and spread operator Dayjs.min behavior with single argument Oct 28, 2024
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant