iamkun / iamkun/dayjs

Inconsistent behavior of .diff() with "month" unit

Open
#755 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

```
console.log(dayjs("2020-02-14").diff(dayjs("2020-02-01"), "month", true));
console.log(dayjs("2020-03-01").diff(dayjs("2020-02-14"), "month", true));
console.log(dayjs("2020-02-14").diff(dayjs("2020-02-01"), "month", true) + dayjs("2020-03-01").diff(dayjs("2020-02-14"), "month", true));
console.log(dayjs("2020-03-01").diff(dayjs("2020-02-01"), "month", true));
```

The result is the following:
```
0.41935483870967744
0.5517241379310345
0.971078976640712
1
```

I have tried with different time units, including adding time and timezone, but no change in the behavior. Other months produce different results, looks like only January and July has it correct.

Chrome 78, Windows 10 if it matters.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.