date-duration
Advanced tools
Comparing version 1.6.0 to 1.7.0
@@ -99,2 +99,14 @@ "use strict"; | ||
}; | ||
var updateParts = function updateParts(parts, operator) { | ||
return Object.keys(parts).reduce(function (result, key) { | ||
if (key === 'T') { | ||
result[key] = updateParts(parts[key], operator); | ||
} else { | ||
result[key] = operator(parts[key]); | ||
} | ||
return result; | ||
}, {}); | ||
}; | ||
/** | ||
@@ -136,5 +148,15 @@ * @constructor | ||
}, { | ||
/** | ||
* Convert to a string in ISO 8601 notation | ||
* @return {string} | ||
*/ | ||
toString: function toString() { | ||
return "P".concat(joinParts(parts, ['Y', 'M', 'W', 'D'])).concat(parts.T ? "T".concat(joinParts(parts.T, ['H', 'M', 'S'])) : ''); | ||
}, | ||
/** | ||
* Add duration to a date | ||
* @param {Date} date | ||
* @return {Date} | ||
*/ | ||
addTo: function addTo(date) { | ||
@@ -145,2 +167,8 @@ return applyParts(clone(date), parts, methods, function (left, right) { | ||
}, | ||
/** | ||
* Subtract duration from a date | ||
* @param {Date} date | ||
* @return {Date} | ||
*/ | ||
subtractFrom: function subtractFrom(date) { | ||
@@ -151,2 +179,8 @@ return applyParts(clone(date), parts, methods, function (left, right) { | ||
}, | ||
/** | ||
* Add (merge) two durations | ||
* @param {Duration} duration | ||
* @return {Duration} | ||
*/ | ||
add: function add(duration) { | ||
@@ -158,2 +192,15 @@ return createDuration({ | ||
}); | ||
}, | ||
/** | ||
* Multiply parts of the duration by a number | ||
* @param {number} multiplier | ||
* @return {Duration} | ||
*/ | ||
multiply: function multiply(multiplier) { | ||
return createDuration({ | ||
P: updateParts(parts, function (value) { | ||
return value * multiplier; | ||
}) | ||
}); | ||
} | ||
@@ -160,0 +207,0 @@ })); |
{ | ||
"name": "date-duration", | ||
"version": "1.6.0", | ||
"version": "1.7.0", | ||
"description": "Manipulate Date objects with ISO 8601-formatted durations", | ||
@@ -5,0 +5,0 @@ "main": "dist/duration.js", |
@@ -32,3 +32,6 @@ date-duration [![Build status](https://api.travis-ci.org/smhg/date-duration.png)](https://travis-ci.org/smhg/date-duration) | ||
### duration.multiply(number) | ||
Multiply individual parts of duration returning a new duration as the result. | ||
### duration.toString() | ||
Convert a duration back to a string in ISO 8601 format. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20051
186
37