iamkun / iamkun/dayjs

Duration add/subtract doesn't take into account how many days in a month

Open
#2,336 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**
methods `add` and `subtract` with duration object doesn't take into account how many days in a month

```javascript
// actual

dayjs('2023-02-01').add(dayjs.duration(1, 'month')) === "2023-03-03"
dayjs('2023-03-01').subtract(dayjs.duration(1, 'month')) === "2023-01-30"
```

**Expected behavior**
```javascript
// expected

dayjs('2023-02-01').add(dayjs.duration(1, 'month')) === "2023-03-01"
dayjs('2023-03-01').subtract(dayjs.duration(1, 'month')) === "2023-02-01"
```

**Information**
- Day.js v1.11.8
- OS: Ubuntu 23.04
- Browser: chrome 114.0.5735.133
- Time zone: GMT +04:00 Europe/Samara

Contributor guide

Open the contributing guide

Research direction

Start by locating the JavaScript implementation of duration handling for add and subtract and the related tests. Reproduce the February and March examples, then add coverage and confirm that month calculations match the expected dates.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
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.