iamkun / iamkun/dayjs

Issue with difference between dates?

Open
#2,432 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**
When calculating the difference between two dates, the result is wrong/unexpected.

` const duration= dayjs.duration(endDate.diff(beginDate));
`
Begin date: $d: Sun May 01 2023 06:00:00 GMT+0200 (Central European Summer Time)
End date: $d: Wed Jun 01 2023 06:00:00 GMT+0200 (Central European Summer Time)
Difference: $d: {years: 0, months: 1, days: 1, hours: 0, minutes: 0, …}

**Expected behavior**
The mathematical value of 1 month and 1 year is correct. But the date value is wrong. The difference between the 1 first of a month and the 1st of the previous, month, is always 1 month. With or without DST, whatever the time zone.

**Information**
- Day.js Version : "1.11.9"
- Time zone: cannot have an impact

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the reported expression, dayjs.duration(endDate.diff(beginDate)), with the May 1 and June 1, 2023 dates from the issue on Day.js 1.11.9. Trace the date-difference and duration handling, then verify that the result matches the expected calendar-month difference across the reported timezone conditions.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.