Liferay.Loader.define("portal-workflow-metrics-web@2.0.42/js/shared/util/duration.es", ['module', 'exports', 'require', 'portal-workflow-metrics-web$moment'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.durationAsMilliseconds = durationAsMilliseconds;
    exports.formatDuration = formatDuration;
    exports.formatHours = formatHours;
    exports.getDurationValues = getDurationValues;

    var _moment = _interopRequireDefault(require("portal-workflow-metrics-web$moment"));

    function _interopRequireDefault(obj) {
      return obj && obj.__esModule ? obj : { "default": obj };
    }

    function _slicedToArray(arr, i) {
      return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest();
    }

    function _nonIterableRest() {
      throw new TypeError("Invalid attempt to destructure non-iterable instance");
    }

    function _iterableToArrayLimit(arr, i) {
      if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) {
        return;
      }var _arr = [];var _n = true;var _d = false;var _e = undefined;try {
        for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) {
          _arr.push(_s.value);if (i && _arr.length === i) break;
        }
      } catch (err) {
        _d = true;_e = err;
      } finally {
        try {
          if (!_n && _i["return"] != null) _i["return"]();
        } finally {
          if (_d) throw _e;
        }
      }return _arr;
    }

    function _arrayWithHoles(arr) {
      if (Array.isArray(arr)) return arr;
    }

    function durationAsMilliseconds(days, fullHours) {
      var _fullHours$split = fullHours.split(':'),
          _fullHours$split2 = _slicedToArray(_fullHours$split, 2),
          hours = _fullHours$split2[0],
          minutes = _fullHours$split2[1];

      return _moment["default"].duration({
        days: days,
        hours: hours,
        minutes: minutes
      }).asMilliseconds();
    }

    function formatDuration(millisecondsDuration) {
      var duration = getDurationValues(millisecondsDuration);
      var durationParts = [{
        label: Liferay.Language.get('days-abbreviation'),
        value: duration.days
      }, {
        label: Liferay.Language.get('hours-abbreviation'),
        value: duration.hours
      }, {
        label: Liferay.Language.get('minutes-abbreviation'),
        value: duration.minutes
      }].filter(function (part) {
        return part.value > 0;
      });

      if (!durationParts.length) {
        return "".concat(duration.seconds ? 1 : 0).concat(Liferay.Language.get('minutes-abbreviation'));
      }

      return durationParts.map(function (part) {
        return "".concat(part.value).concat(part.label);
      }).join(' ');
    }

    function formatHours(hours, minutes) {
      var padHours = function padHours(value) {
        return value && value.toString().padStart(2, '0') || '00';
      };

      if (hours || minutes) {
        return [hours, minutes].map(padHours).join(':');
      }

      return '';
    }

    function getDurationValues(durationValue) {
      var fullDuration = _moment["default"].duration(durationValue);

      return {
        // eslint-disable-next-line radix
        days: parseInt(fullDuration.asDays()) || null,
        hours: fullDuration.hours() || null,
        minutes: fullDuration.minutes() || null,
        seconds: fullDuration.seconds() || null
      };
    }
    //# sourceMappingURL=duration.es.js.map
  }
});
//# sourceMappingURL=duration.es.js.map