iamkun / iamkun/dayjs

Adding duration object to dayjs object leads to Invalid date.

Open
#1,623 5 comments 4 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**
```
const day = dayjs();
console.log(day.format());

const modifiedDay = day.add(dayjs.duration({ days: 1 }));
console.log(modifiedDay.format());
```

![image](https://user-images.githubusercontent.com/1250540/131868314-d8ea5233-6971-4585-b9e1-ae215a2650bd.png)

This kind of action should be supported according to the dayjs documentation:
https://day.js.org/docs/en/manipulate/add

**Expected behavior**
It should add one day to the object and print the correct result. Instead, it creates an invalid date.

**Information**
- Day.js v1.10.6
- OS: macOS Big Sur (11.5.2)
- Browser: Google Chrome 92.0.4515.159 (Official Build) (x86_64)
- Time zone: Europe/Berlin (we are currently on UTC+02:00)

Contributor guide

Open the contributing guide

Research direction

Start with the provided reproduction using dayjs.add and dayjs.duration, then trace how the duration plugin value is handled by the add API. Confirm the behavior against the documented add example and establish a regression check showing that adding one day produces a valid date.

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
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.