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
One year duration gives me back 1 year and 5 days ??? #1466
Comments
Based on my understanding of durations, this is because of weirdness in what equates to a month. Moment's durations define a month as being 30 days. However, this means that a year (12 months) has 360 instead of 365 days. Since your first duration knew it was supposed to be a year (365 days) it would have worked properly, but your second duration didn't. It consumed the milliseconds and converted upwards. Whether or not this is intended behavior or even what's actually happening, I don't know. It does seem to be a plausible explanation, though. |
Yeah. Your best bet is to create a duration with the right units (1 year is better than the ms duration). If you add a duration to moment we try to be smart, if not file a bug for that. Cloning a duration should preserve those properties, but dont go through ms - it ruins it all. |
well I have a function which returns only ms, so when I want to know what the ms translates to I use moments duration, but get back incorrect results which is annoying :S |
You could try creating a moment from the milliseconds and comparing it to a moment at time 0. It's not a perfect solution, but it may give you more reliable results. Durations really aren't good for doing any kind of accurate measurements, particularly from milliseconds and even more particularly when those milliseconds span multiple months. |
Closing for now. Maybe someday we'll get some nice logic that does precise rollups (like in countdown.js or Precise Diff), but I don't see a big need to address this now. |
Hi, I know its unnecessary to call
asMilliseconds()
on the duration and then make a new duration, but to mimic my code as closely as possible without cluttering the example with business logic i chose to keep it.Also I have not tested just calling
var mom = moment.duration({ y: 1 }); var days = mom.days();
,I figured first getting milliseconds with asMilliseconds() and then passing the result into a new duration may cause the bug.
The above gives me the following result:
I don't understand why...?
The text was updated successfully, but these errors were encountered: