'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = ElapsedTime;

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _propTypes = require('prop-types');

var _propTypes2 = _interopRequireDefault(_propTypes);

var _formatMessage = require('../../../common/format-message');

var _formatMessage2 = _interopRequireDefault(_formatMessage);

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

function ElapsedTime(_ref) {
  var eventTime = _ref.eventTime,
      startTime = _ref.startTime;

  var difference = eventTime - startTime;
  var totalSeconds = difference / 1000;
  var hours = Math.floor(totalSeconds / 3600);
  var remainder = totalSeconds - hours * 3600;
  var minutes = Math.floor(remainder / 60);
  var seconds = remainder - minutes * 60;

  // Intl.DurationFormat doesn't exist yet.
  // https://github.com/tc39/ecma402/issues/47
  // Let translators provide patterns for durations
  var displayTime = hours ? _formatMessage2.default.number(hours, 'decimal_2_min_integer_no_fraction', 'it') + ':' + _formatMessage2.default.number(minutes, 'decimal_2_min_integer_no_fraction', 'it') + ':' + _formatMessage2.default.number(seconds, 'decimal_2_min_integer_no_fraction', 'it') : _formatMessage2.default.number(minutes, 'decimal_2_min_integer_no_fraction', 'it') + ':' + _formatMessage2.default.number(seconds, 'decimal_2_min_integer_no_fraction', 'it');

  return _react2.default.createElement(
    'span',
    null,
    displayTime
  );
}

ElapsedTime.propTypes = {
  eventTime: _propTypes2.default.instanceOf(Date).isRequired,
  startTime: _propTypes2.default.instanceOf(Date).isRequired
};