Skip to content

Releases: jsmreese/moment-duration-format

Version 2.3.2

05 Jun 14:06
Compare
Choose a tag to compare

Issues Fixed

  • Actually fix the crash on node from version 2.3.0. Thanks @pdcastro and @hyuraku. Sorry about that. Again.

Version 2.3.1

04 Jun 12:34
Compare
Choose a tag to compare

Issues Fixed

  • Version 2.3.0 crashed on node because of an unguarded use of window. Thanks @pdcastro and @thib3113. Sorry about that.

Version 2.3.0

03 Jun 23:13
Compare
Choose a tag to compare

Issues Fixed

  • Add Intl.NumberFormat support, and cache NumberFormat objects when reused. This cuts execution time more or less in half. Thank you @ticky! (#122)

Version 2.2.2

17 Feb 00:44
Compare
Choose a tag to compare

Issues Fixed

  • Negative sign is not placed properly for negative durations when trim is false. (#104)

  • Exception on older versions of moment.js because moment.duration.fn.isValid is not a function. (#103)

Version 2.2.1

22 Jan 02:55
Compare
Choose a tag to compare

Issues Fixed

  • Rounding errors for some output when using toLocaleString in Microsoft environments (IE11, Edge, Windows Phone). (#95)

  • Format errors on zero-value tokens when using useSignificantDigits on HTC environments (HTC Browser). (#96)

Version 2.2.0

16 Jan 13:35
Compare
Choose a tag to compare

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

  • #93 and #94 affect Microsoft environments (Edge, IE11, Windows Phone) when using toLocaleString (#95)

  • HTC Devices can format zero-value tokens as "0.0" instead of "0" when using significant digits. (#96)

Version 2.1.1

30 Dec 02:33
Compare
Choose a tag to compare

Bug Fixes

  • String#includes not supported in some environments including IE 11 (#89)

  • Incorrect token length when trim: false (#91)

Version 2.1.0

21 Dec 23:27
Compare
Choose a tag to compare

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)

Version 2.0.1

14 Dec 18:00
Compare
Choose a tag to compare

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. The userLocale option now defaults to the locale set in moment.js, retrieved via moment.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

13 Dec 19:55
Compare
Choose a tag to compare

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 intuitive trim, useSignificantDigits, stopTrim, minValue, and maxValue, and trunc.

  • 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 to true.

  • 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 via userLocale. (!) Note that version 2.2.0 restores the decimalSeparator option when using the fallback format function.

  • The milliseconds token now has special handling for a token length of 2 to support templates like mm: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.