Liferay.Loader.define("portal-workflow-metrics-web@2.0.42/js/components/filter/util/timeRangeUtil.es", ['module', 'exports', 'require', '../../../shared/util/date.es', '../../../shared/util/moment.es'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    Object.defineProperty(exports, "isValidDate", {
      enumerable: true,
      get: function get() {
        return _date.isValidDate;
      }
    });
    exports.parseDateItems = exports.parseDateMoment = exports.getTimeRangeParams = exports.getCustomTimeRange = exports.formatTimeRange = exports.formatDescriptionDate = exports.formatDateTime = exports.convertQueryDate = void 0;

    var _date = require("../../../shared/util/date.es");

    var _moment = _interopRequireDefault(require("../../../shared/util/moment.es"));

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

    function ownKeys(object, enumerableOnly) {
      var keys = Object.keys(object);if (Object.getOwnPropertySymbols) {
        var symbols = Object.getOwnPropertySymbols(object);if (enumerableOnly) symbols = symbols.filter(function (sym) {
          return Object.getOwnPropertyDescriptor(object, sym).enumerable;
        });keys.push.apply(keys, symbols);
      }return keys;
    }

    function _objectSpread(target) {
      for (var i = 1; i < arguments.length; i++) {
        var source = arguments[i] != null ? arguments[i] : {};if (i % 2) {
          ownKeys(Object(source), true).forEach(function (key) {
            _defineProperty(target, key, source[key]);
          });
        } else if (Object.getOwnPropertyDescriptors) {
          Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
        } else {
          ownKeys(Object(source)).forEach(function (key) {
            Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
          });
        }
      }return target;
    }

    function _defineProperty(obj, key, value) {
      if (key in obj) {
        Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true });
      } else {
        obj[key] = value;
      }return obj;
    }

    var convertQueryDate = function convertQueryDate() {
      var date = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
      var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'L';
      return _moment["default"].utc(decodeURIComponent(date), null, 'en').format(format);
    };

    exports.convertQueryDate = convertQueryDate;

    var formatDateTime = function formatDateTime(date, format, isEndDate) {
      var dateTime = parseDateMoment(date, format || 'L');
      dateTime = isEndDate ? dateTime.endOf('day') : dateTime.startOf('day');
      return dateTime.format(_date.defaultDateFormat);
    };

    exports.formatDateTime = formatDateTime;

    var formatDescriptionDate = function formatDescriptionDate(date) {
      return (0, _date.formatDate)(decodeURIComponent(date), (0, _date.getLocaleDateFormat)('ll'), _date.defaultDateFormat);
    };

    exports.formatDescriptionDate = formatDescriptionDate;

    var formatTimeRange = function formatTimeRange(timeRange, isAmPm) {
      var dateEnd = timeRange.dateEnd,
          dateStart = timeRange.dateStart;

      if (!dateEnd && !dateStart) {
        return null;
      }

      var dateEndMoment = _moment["default"].utc(dateEnd);

      var dateStartMoment = _moment["default"].utc(dateStart);

      var _getFormatPattern = getFormatPattern(dateEndMoment, dateStartMoment, isAmPm),
          dateEndPattern = _getFormatPattern.dateEndPattern,
          dateStartPattern = _getFormatPattern.dateStartPattern;

      return "".concat(dateStartMoment.format(dateStartPattern), " - ").concat(dateEndMoment.format(dateEndPattern));
    };

    exports.formatTimeRange = formatTimeRange;

    var getCustomTimeRange = function getCustomTimeRange(dateEnd, dateStart) {
      var customTimeRange = {
        active: false,
        dateEnd: dateEnd ? decodeURIComponent(dateEnd) : undefined,
        dateStart: dateStart ? decodeURIComponent(dateStart) : undefined,
        dividerAfter: true,
        id: 'custom',
        name: Liferay.Language.get('custom-range')
      };
      customTimeRange.resultName = "".concat(formatDescriptionDate(dateStart), " - ").concat(formatDescriptionDate(dateEnd));
      return customTimeRange;
    };

    exports.getCustomTimeRange = getCustomTimeRange;

    var getFormatPattern = function getFormatPattern(dateEndMoment, dateStartMoment, isAmPm) {
      var dateStartPattern = Liferay.Language.get('mmm-dd-yyyy');

      if (dateEndMoment.diff(dateStartMoment, 'days') <= 1) {
        if (isAmPm) {
          dateStartPattern = Liferay.Language.get('mmm-dd-hh-mm-a');
        } else {
          dateStartPattern = Liferay.Language.get('mmm-dd-hh-mm');
        }
      } else if (dateEndMoment.diff(dateStartMoment, 'years') < 1) {
        dateStartPattern = Liferay.Language.get('mmm-dd');
      }

      var dateEndPattern = dateStartPattern;

      if (dateEndMoment.diff(dateStartMoment, 'days') > 90) {
        dateEndPattern = Liferay.Language.get('mmm-dd-yyyy');
      }

      return {
        dateEndPattern: dateEndPattern,
        dateStartPattern: dateStartPattern
      };
    };

    var getTimeRangeParams = function getTimeRangeParams() {
      var dateStartEncoded = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
      var dateEndEncoded = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
      var params = {};
      var dateEnd = decodeURIComponent(dateEndEncoded);
      var dateStart = decodeURIComponent(dateStartEncoded);

      if ((0, _date.isValidDate)(dateEnd, _date.defaultDateFormat) && (0, _date.isValidDate)(dateStart, _date.defaultDateFormat)) {
        params = {
          dateEnd: dateEnd,
          dateStart: dateStart
        };
      }

      return params;
    };

    exports.getTimeRangeParams = getTimeRangeParams;

    var parseDateMoment = function parseDateMoment(date) {
      var format = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'L';
      return _moment["default"].utc(date, format, 'en');
    };

    exports.parseDateMoment = parseDateMoment;

    var parseDateItems = function parseDateItems(isAmPm) {
      return function (items) {
        return items.map(function (item) {
          var parsedItem = _objectSpread({}, item, {
            dateEnd: item.dateEnd,
            dateStart: item.dateStart,
            key: item.key
          });

          if (parsedItem.key !== 'custom') {
            parsedItem.description = formatTimeRange(item, isAmPm);
          }

          return parsedItem;
        });
      };
    };

    exports.parseDateItems = parseDateItems;
    //# sourceMappingURL=timeRangeUtil.es.js.map
  }
});
//# sourceMappingURL=timeRangeUtil.es.js.map