yarn moment-duration-format 2.1.0
Version 2.1.0

latest releases: 2.3.2, 2.3.1, 2.3.0...
6 years ago

New and Updated Features

This version adds moment.duration.format, which allows coordinated formatting of multiple durations.

Not to be confused with moment.duration.fn.format, the existing function that allows formatting of a single duration.

The new function accepts an array of durations, in addition to all of the arguments and options available with the individual duration format function.

Trimming is coordinated across all of the durations.

moment.duration.format([
    moment.duration(1, "second"),
    moment.duration(1, "minute"),
    moment.duration(1, "hour")
], "d [days] hh:mm:ss");
// ["0:00:01", "0:01:00", "1:00:00"]

moment.duration.format([
    moment.duration(1, "minute"),
    moment.duration(1, "day")
], "w [weeks], d [days], h [hours], m [minutes], s [seconds]", { trim: "all" });
// ["0 days, 1 minute", "1 day, 0 minutes"]

In addition to the new moment.duration.format function, this version brings the following updates:

  • The largest option is updated so that the output is more intuitive. The largest tokens are output, starting with the first token that has a non-zero value. In version 2.0, only tokens with non-zero values were output, leading to some unintuitive results.

  • The largest, minValue, maxValue, and useSignificantDigits options all function with trim now.

  • When largest, maxValue, or useSignificantDigits is set, trim is defaulted to "all".

Bug Fixes

  • Fix error when template is trimmed and useSignificantDigits is set. (#87)

  • Fix error for negative durations when stopTrim is set. (#86)

  • Fix error for rounded values that do not bubble to a larger-magnitude unit. (#84)

Don't miss a new moment-duration-format release

NewReleases is sending notifications on new releases.