iamkun / iamkun/dayjs

dayjs duration Incorrect calculation

Open
#2,726 5 comments 1 reaction 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**
A clear and concise description of what the bug is.
const duration2023 = this.$dayjs.duration(this.$dayjs('2023-12-31 23:59:59').diff(this.$dayjs('2023-01-01 00:00:00')));
out: {
"years": 0,
"months": 12,
"days": 4,
"hours": 23,
"minutes": 59,
"seconds": 59,
"milliseconds": 0
}

const duration2024 = this.$dayjs.duration(this.$dayjs('2024-12-31 23:59:59').diff(this.$dayjs('2024-01-01 00:00:00')));
out: {
"years": 1,
"months": 0,
"days": 0,
"hours": 23,
"minutes": 59,
"seconds": 59,
"milliseconds": 0
}

years 0&&1
**Expected behavior**
A clear and concise description of what you expected to happen.
Consistent year
**Information**
- Day.js Version [v1.11.13]
- OS: [WIN 11]
- Browser [edge 128.0.2739.67 ]
- Time zone: [GMT-08:00 ]

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the duration calculations from the issue with Day.js v1.11.13, comparing the 2023 and 2024 date ranges. Trace how the duration result derives years, months, and days, then verify that the two equivalent examples produce consistent year behavior.

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.