date-duration
Advanced tools
Comparing version 1.3.0 to 1.3.1
@@ -11,2 +11,6 @@ 'use strict'; | ||
var _taggedTemplateLiteral2 = require('babel-runtime/helpers/taggedTemplateLiteral'); | ||
var _taggedTemplateLiteral3 = _interopRequireDefault(_taggedTemplateLiteral2); | ||
var _freeze = require('babel-runtime/core-js/object/freeze'); | ||
@@ -20,2 +24,10 @@ | ||
var _map = require('babel-runtime/core-js/map'); | ||
var _map2 = _interopRequireDefault(_map); | ||
var _isInteger = require('babel-runtime/core-js/number/is-integer'); | ||
var _isInteger2 = _interopRequireDefault(_isInteger); | ||
var _toArray2 = require('babel-runtime/helpers/toArray'); | ||
@@ -25,6 +37,2 @@ | ||
var _map = require('babel-runtime/core-js/map'); | ||
var _map2 = _interopRequireDefault(_map); | ||
var _typeof2 = require('babel-runtime/helpers/typeof'); | ||
@@ -34,2 +42,5 @@ | ||
var _templateObject = (0, _taggedTemplateLiteral3.default)(['', 'Y', 'M', 'W', 'D'], ['', 'Y', 'M', 'W', 'D']), | ||
_templateObject2 = (0, _taggedTemplateLiteral3.default)(['', 'H', 'M', 'S'], ['', 'H', 'M', 'S']); | ||
exports.default = createDuration; | ||
@@ -55,2 +66,14 @@ | ||
}; | ||
var stripEmptyElements = function stripEmptyElements(_ref) { | ||
for (var _len = arguments.length, values = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
values[_key - 1] = arguments[_key]; | ||
} | ||
var _ref2 = (0, _toArray3.default)(_ref), | ||
elements = _ref2.slice(1); | ||
return elements.reduce(function (result, element, index) { | ||
return '' + result + ((0, _isInteger2.default)(values[index]) ? '' + values[index] + element : ''); | ||
}, ''); | ||
}; | ||
var parser = /P(?:(\d+)Y)?(?:(\d+)M)?(?:(\d+)W)?(?:(\d+)D)?(?:T(?:(\d+)H)?(?:(\d+)M)?(?:(\d+)S)?)?/; | ||
@@ -92,3 +115,3 @@ var dateMethods = new _map2.default([['year', 'FullYear'], ['month', 'Month'], ['week', 'Date'], ['day', 'Date'], ['hour', 'UTCHours'], ['minute', 'UTCMinutes'], ['second', 'UTCSeconds']]); | ||
toString: function toString() { | ||
return 'P' + (year !== undefined ? year + 'Y' : '') + (month !== undefined ? month + 'M' : '') + (week !== undefined ? week / 7 + 'W' : '') + (day !== undefined ? day + 'D' : '') + (hour !== undefined || minute !== undefined || second !== undefined ? 'T' + (hour !== undefined ? hour + 'H' : '') + (minute !== undefined ? minute + 'M' : '') + (second !== undefined ? second + 'S' : '') : ''); | ||
return ('P' + stripEmptyElements(_templateObject, year, month, week / 7, day) + 'T' + stripEmptyElements(_templateObject2, hour, minute, second)).replace(/T$/, ''); | ||
}, | ||
@@ -95,0 +118,0 @@ addTo: function addTo(date) { |
{ | ||
"name": "date-duration", | ||
"version": "1.3.0", | ||
"version": "1.3.1", | ||
"description": "Manipulate Date objects with ISO 8601-formatted durations", | ||
@@ -5,0 +5,0 @@ "main": "dist/duration.js", |
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
14871
149