"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

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

var _react = _interopRequireDefault(require("react"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _formatMessage = _interopRequireDefault(require("@instructure/quiz-common/lib/format-message"));

var _decimal_2_min_integer_no_fraction_de_number = Intl.NumberFormat("de", { style: "decimal" }).format;

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 ? _decimal_2_min_integer_no_fraction_de_number(hours) + ":" + _decimal_2_min_integer_no_fraction_de_number(minutes) + ":" + _decimal_2_min_integer_no_fraction_de_number(seconds) : _decimal_2_min_integer_no_fraction_de_number(minutes) + ":" + _decimal_2_min_integer_no_fraction_de_number(seconds);
  return _react.default.createElement("span", null, displayTime);
}

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