moment-duration-format
Advanced tools
Comparing version 2.0.0 to 2.0.1
{ | ||
"name": "moment-duration-format", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "A moment.js plugin for formatting durations.", | ||
@@ -5,0 +5,0 @@ "main": "lib/moment-duration-format.js", |
@@ -1,4 +0,4 @@ | ||
/*! Moment Duration Format v2.0.0 | ||
/*! Moment Duration Format v2.0.1 | ||
* https://github.com/jsmreese/moment-duration-format | ||
* Date: 2017-12-13 | ||
* Date: 2017-12-14 | ||
* | ||
@@ -311,2 +311,3 @@ * Duration format plugin function for the Moment.js library | ||
var asMilliseconds = this.asMilliseconds(); | ||
var asMonths = this.asMonths(); | ||
@@ -319,3 +320,7 @@ // Treat invalid durations as having a value of 0 milliseconds. | ||
var isNegative = asMilliseconds < 0; | ||
// Two shadow copies are needed because of the way moment.js handles | ||
// duration arithmetic for years/months and for weeks/days/hours/minutes/seconds. | ||
var remainder = moment.duration(Math.abs(asMilliseconds), "milliseconds"); | ||
var remainderMonths = moment.duration(Math.abs(asMonths), "months"); | ||
@@ -438,3 +443,3 @@ // Parse arguments. | ||
// Determine user's locale. | ||
var userLocale = settings.userLocale || window.navigator.userLanguage || window.navigator.language; | ||
var userLocale = settings.userLocale || moment.locale(); | ||
@@ -576,4 +581,10 @@ var useLeftUnits = settings.useLeftUnits; | ||
// Get the raw value in the current units. | ||
var rawValue = remainder.as(momentType); | ||
var rawValue; | ||
if (momentType === "years" || momentType === "months") { | ||
rawValue = remainderMonths.as(momentType); | ||
} else { | ||
rawValue = remainder.as(momentType); | ||
} | ||
var wholeValue = Math.floor(rawValue); | ||
@@ -609,2 +620,3 @@ var decimalValue = rawValue - wholeValue; | ||
remainder.subtract(wholeValue, momentType); | ||
remainderMonths.subtract(wholeValue, momentType); | ||
@@ -611,0 +623,0 @@ return { |
{ | ||
"name": "moment-duration-format", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "A moment.js plugin for formatting durations.", | ||
@@ -5,0 +5,0 @@ "main": "lib/moment-duration-format.js", |
@@ -685,3 +685,3 @@ # Moment Duration Format | ||
Numerical output is rendered using the locale of the user's environment. Set the `userLocale` option to render numerical output using a different locale. | ||
Numerical output is rendered using the locale set in moment.js, retrieved via `moment.locale()`. Set the `userLocale` option to render numerical output using a different locale. | ||
@@ -688,0 +688,0 @@ ```javascript |
@@ -20,2 +20,11 @@ $(document).ready(function() { | ||
test("Trim errors from years/months to weeks/days", function () { | ||
equal(moment.duration(1, "year").format("y [years], d [days], h [hours]"), "1 year, 0 days, 0 hours"); | ||
equal(moment.duration(1, "year").format("y [years], M [months], d [days], h [hours]"), "1 year, 0 months, 0 days, 0 hours"); | ||
equal(moment.duration(1, "year").format("y [years], w [weeks], d [days], h [hours]"), "1 year, 0 weeks, 0 days, 0 hours"); | ||
equal(moment.duration(1, "year").format("y [years], h [hours]"), "1 year, 0 hours"); | ||
equal(moment.duration(1, "month").format("M [months], d [days]"), "1 month, 0 days"); | ||
equal(moment.duration(1, "month").format("M [months], w [weeks]"), "1 month, 0 weeks"); | ||
}); | ||
test("Trim Left", function () { | ||
@@ -22,0 +31,0 @@ equal(moment.duration(1, "seconds").format("m s"), "1"); |
548763
15059