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
Manipulating days with decimal numbers ignores hours #2013
Comments
Hi, the moment.js behaviour is the same, it seems to be a lack of docs in dayjs library: Moment.js docs: Here you can find more info: moment/moment#2430 (comment) Upd: strange behaviour with subtracting 1.5 day, the date should be 2 days ago. Seems to be a bug for me if my assumes with day rounding are correct. Line 230 in b5b7be1
-1.5 is rounded to -1 and 1.5 is rounded to 2 Momentjs is using absolute rounding, that's why result is different. |
So it looks to me. To my knowledge, rounding to the nearest integer for negative numbers is done with the absolute value (and adding the sign again after rounding). How about a PR? I will do a PR for the documentation as the rounding to the nearest integer (as moment does) should / must be part of the documentation. |
I think we should wait @iamkun to discuss this behaviour, what do you think about it? I can create PR for this if we come to common decision about dayjs behaviour |
Of course you are right. IMO one of the basic definitions for dayjs is that it behaves just like moment (ok, there are a few exceptions :-). In this regard this is at least another difference. But as this would be a breaking change (if not of the documentation that says nothing about it, so at least regarding the functionality), perhaps this should become an action point for dayjs 2.0. @iamkun is there a place, where those requirements for dayjs 2.0 could be documented? PS: @Bykiev you are pretty fast responding to issues 🥇 👍 😄 |
Totally agree, this change is better suited for dayjs 2.0
Yeah, recently we've migrated our project from moment.js to dayjs. We've spent many times analysing open issues to discover the possible issues (still waiting response from @iamkun in #1921). That's why I've fresh knowledges about it and I like to help new users to use this library. |
Thanks for your elaborations. I agree that the docs need to at least warn the user about this behavior. I can also understand why you want to behave dayjs the same as momentjs but at some point you have to consider removing bugs that moment had and I would consider this clearly as a bug since most other units are able to subtract/add decimal values. A fix in dayjs 2.0 would be OK. We implemented a workaround for now. |
It's not a bug in moment.js, see explanation here: moment/moment#2430 (comment). |
Is this planned for |
Describe the bug
When manipulating a date with unit type
day
and an arbitrary decimal number does not manipulate the time of the date.Expected behavior
The time is manipulated as well.
Information
Stackblitz reproduction:
https://stackblitz.com/edit/js-akaprq?file=index.js
The text was updated successfully, but these errors were encountered: