jsmreese / moment-duration-format

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

a negative number(-1 days) appears in the result #135

Open thelastto opened 4 years ago

thelastto commented 4 years ago
moment.duration(5270100, 'seconds').format('y [years] M [months] D [days] h [hours] m [minutes] s [seconds]', {
    largest: 3
  })
// "2 months -1 days 23 hours"
jsmreese commented 4 years ago

Thank you. More floating point rounding issues and related to #121.

BannerBomb commented 4 years ago

I get to for weeks

moment.duration(28941549102).format({ template: 'y [years], M [months], w [weeks], d [days], h [hours], m [minutes], s [seconds], S [milliseconds]', largest: 2, trim: 'both mid', useSignificantDigits: true })
// 11 months and -1 weeks

I made this comment on a sunday when the issue was happening now that it's monday the issue is fixed :man_shrugging:

gabrielbrise commented 2 years ago

I'm having the same problem and I made this fiddlejs https://jsfiddle.net/51fzqxbs/ which recreates it. Found out that the bug was introduced in 2.0.0 (if you change the version of the cdn script between 1.3.0 and 2.0.0 you can see it changing from returning a 0 to -1 day)