iamkun / iamkun/dayjs

Dayjs.min behavior with single argument

Open
#2,759 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
48.7k
Forks
2.5k
PR merge metrics
No merged PRs in 30d

Description

**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

Contributor guide

Open the contributing guide

Research direction

Start at the dayjs.min entry point and compare the single-date call with the array form shown in the report. Add coverage for a valid single-argument date, then verify that the reported expected result is returned while the empty-list behavior remains covered.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.