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
, anduseSignificantDigits
options all function withtrim
now. -
When
largest
,maxValue
, oruseSignificantDigits
is set,trim
is defaulted to"all"
.