-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Duration between dates seems to be incorrect #1433
Comments
Just to add to @simeon9696 's issue, using the https://runkit.com/6052c5915dac89001a8e3602/606151bf64ef4e00192ea162 |
I just noticed a bug and it seems related to this issue: // dayjs version 1.10.5
import dayjs from 'dayjs';
import dayjsDurationPlugin from 'dayjs/plugin/duration';
const a = dayjs('3/19/2018');
const b = dayjs('3/17/2021');
const diff = b.diff(a, 'day'); // => 1094 correct
dayjs.duration(diff, 'days'); // => { years: 2, months: 12, days: 4 } incorrect I would expect the output to be |
is there any movement on this? just stumbled across it myself |
Is there any further on this, please? I too have encountered this issue. |
any update? |
I encountered this issue today too. Example
Thoughts As the code @avand pasted above actually also shows, the issue is the interaction between The method If you then pass this milliseconds result to That's my theory anyway. Workaround? Until this is fixed, a workaround might be to use So say for me, for now, I want my interface to recognise that from 2021-09-21 to 2050-09-21 is 29 years but that 2021-09-21 to 2050-09-20 (just a day less) is still 28 years. I can do this with:
If I then pass this onto Summary of problem In short I think both the way |
Further evidence for the above observed in comment on a related issue. Brief thread on more accurate duration requirements also adds to this. |
Same problem here: |
Here too: const diffMonth = to.diff(from, 'month');
console.log({fromParam, toParam, diffMonth, diffMonth2: to.get('month') - from.get('month')});
"dayjs": "^1.11.7" |
In my experience, you can't rely on the duration method when calculating duration in months or years. This is due to the fact that months do not contain the same number of days, and the calculations use one fixed value: ~30.41666 (30 days 10 hours). Example:
|
+1 |
Describe the bug
Duration seems to be incorrect. The difference between March 29th, 2020 and March 28th 2021 should be less than 12 months
Expected behavior
Calculating the difference between two days one year apart from each other should yield a difference of one year.
Information
I'm trying to get the difference between two dates:
I do that with:
This yields
diffDuration
as:Which doesn't make sense to me? It shouldn't 12 months and 4 days. Also, I think that if it is 12 months and 4 days, then years should be 1 but in this instance it's 0.
Is this expected behaviour?
The text was updated successfully, but these errors were encountered: