Releases: jsmreese/moment-duration-format
Version 2.3.2
Version 2.3.1
Version 2.3.0
Version 2.2.2
Version 2.2.1
Version 2.2.0
Fallback Number Formatting
This version adds a fallback number format function to fully support devices and environments that do not implement a complete version of Number#toLocaleFormat
.
Localization options for the fallback number format function are available: decicmalSeparator
, groupingSeparator
, and grouping
.
The plugin executes a feature test for toLocaleString
on initialization to determine which number format function it will use. You may force the plugin to use the fallback number format function in all environments by setting useToLocaleString
to false
.
Issues Fixed
-
toLocaleString
is not fully implemented in many environments (#90) -
Format errors due to floating point rounding issues in JavaScript (#93)
-
Format errors due to floating point rounding issues within Moment.js (#94)
Known Issues in Version 2.2.0
Version 2.1.1
Version 2.1.0
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"
.
Bug Fixes
Version 2.0.1
Because nothing is ever perfect.
This version fixes two issues in version 2.0.0:
-
#81 JavaScript error when using the plugin with Node.js because
window
is undefined. TheuserLocale
option now defaults to the locale set in moment.js, retrieved viamoment.locale()
. -
#82 Trim errors for durations greater than one month and templates that included tokens of lesser magnitude. Duration arithmetic is handled differently in moment.js for months and years than it is for days and lesser types. The plugin now handles that transition correctly.
Version 2.0.0
This release is a complete revamp of the moment duration format plugin, incorporating and implementing almost all of the feedback from the past four years that version 1 has been in the wild.
Fixes and Features
-
Localization support. Numerical output is formatted via
toLocaleString
, and unit labels are formatted via custom extensions to moment's locale object. This allows a range of localization features, including label style and pluralization, decimal separator and digit grouping, and significant digits output. -
Proper UMD packaging, with support for alternate moment instances such as moment-timezone.
-
Updated format options, including
largest
, expanded and more intuitivetrim
,useSignificantDigits
,stopTrim
,minValue
, andmaxValue
, andtrunc
. -
Bug fixes around negative durations, rounding, default output ambiguity, and more, plus a boat load of tests.
Breaking Changes
Upgrading from version 1 should be a simple drop-in replacement, with a few exceptions:
-
The default behaviour in version 2 is to round values rather than truncate, as was in version 1. To restore truncation, set
trunc
totrue
. -
The
decimalSeparator
option is removed. That functionality is now provided through the locale, which defaults to that of the user's environment for numerical formatting. This can be specified in code viauserLocale
. (!) Note that version 2.2.0 restores thedecimalSeparator
option when using the fallback format function. -
The milliseconds token now has special handling for a token length of
2
to support templates likemm:ss:SS
. -
The moment types and tokens are no longer configurable.
-
You may need to remove any hacks in place to work around packaging and other issues in version 1.