jsmreese / moment-duration-format

Format function plugin for the Moment Duration object.
MIT License
968 stars 121 forks source link

Inserting the value 13 will result in a value 12 #13

Closed RuudH closed 10 years ago

RuudH commented 10 years ago

moment.duration(13, 'minutes').format("HH:mm [uur]", { trim: false }); Will return "00:12 uur"

I would expected "00:13 uur"

Thanks!

jsmreese commented 10 years ago

What environment are you in? I see the expected return of "00:13 uur".

RuudH commented 10 years ago

I'm running this on IIS 7.5 on my development VM running windows 7 64bit. I see the same results in IE11 and Chrome. Any more information you would like?

jsmreese commented 10 years ago

Here's a jsbin reproducing the issue. http://jsbin.com/fuvohonameka/1/edit

I had been testing with Moment.js version 2.4.0. Upgrading to the latest Moment.js (version 2.8.2) breaks quite a bit.

Not sure what the issue is, but I'm looking into it.

jsmreese commented 10 years ago

For the record, the breaking changes were introduced in Moment.js version 2.8.0 at the end of July. Moment Duration Format passes all tests on Moment.js version 2.7.0.

jsmreese commented 10 years ago

It looks like there's an error in the moment.duration.as and .asMinutes methods that was introduced in Moment.js 2.8.0..

moment.duration(12, "minutes").as("minutes");
and
moment.duration(12, "minutes").asMinutes();
// 12

moment.duration(13, "minutes").as("minutes");
and
moment.duration(13, "minutes").asMinutes();
// 12.999999999999998

This happens with moment durations of 13, 26, 27, 31, 33, 52, 54 minutes, and possibly other combinations of values and units. I have a little more digging to do before I file an issue on Moment.js.

RuudH commented 10 years ago

Hi, Thanks for the information. I did not make the connection with the new moment.js. It happens in rare occations in our app so i didn't notice it directly after updating to 2.8.1. Thanks for your fast actions!!

jsmreese commented 10 years ago

This issue is fixed in Moment.js version 2.8.3, which was published on September 4.

RuudH commented 10 years ago

Great thank you for your help and feedback!