jsmreese / moment-duration-format

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

Pluralisation of rounded values not quite right #78

Closed sj26 closed 6 years ago

sj26 commented 6 years ago

Thanks for the great library!

We noticed that pluralisation on current master, is a bit odd when formatting partial values:

equal(moment.duration(1.25, "s").format("s [secs]"), "1 sec"); // passes
equal(moment.duration(1.5, "s").format("s [secs]"), "2 secs"); // passes
equal(moment.duration(1.75, "s").format("s [secs]"), "2 secs"); // fails - gets "2 sec"
equal(moment.duration(2, "s").format("s [secs]"), "2 secs"); // passes

It seems the code floors the value when considering whether to singularise/pluralise the unit name, but it still outputs a rounded value for the actual unit value itself.

jsmreese commented 6 years ago

Thanks for the note. I'd noticed that issue myself over the weekend, too. I'll have it fixed in the next push.