jsmreese / moment-duration-format

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

Rounded token values do not bubble up to higher-order tokens. e.g. `h:mm` format shows '1:60' when duration is 2 hours #84

Closed oluckyman closed 6 years ago

oluckyman commented 6 years ago
moment.duration(
  moment('2017-12-17T02:00:00+00:00') -
  moment('2017-12-17T00:00:30+00:00')
).format('h:mm') // returns: '1:60' instead of '2:00'
jsmreese commented 6 years ago

Thank you! This is happening because of the rounding inherent in toLocaleString. I'll check it out.

Similarly failing:

moment.duration({ hours: 2, seconds: -30 }).format("h:mm"); // "1:60"
moment.duration(7170, "seconds").format("h:mm"); // "1:60"
moment.duration(2879, "minutes").format("d[d] h[h]"); // "1d 24h"
moment.duration(335, "hours").format("w[w], d[d]"); // "1w, 7d"
moment.duration({ days: 7, seconds: -30 }).format("w[w] d[d] h:mm", { trim: "all" }); // "6d 23:60"
jsmreese commented 6 years ago

Also happens with useSignificantDigits:

moment.duration({ hours: 2, seconds: -60 }).format("h:mm", { precision: 2, useSignificantDigits: true });
// 1:60