"use strict";

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

function _react() {
  const data = _interopRequireDefault(require("react"));

  _react = function _react() {
    return data;
  };

  return data;
}

var _constants = _interopRequireDefault(require("../constants"));

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

const interval = _constants.default.interval;
const delegates = _constants.default.delegates;
/**
 * 周期开始时间
 */

function beginEpochTime() {
  return _constants.default.net.beginDate;
}
/**
 * 周期时间
 * @param {time} time 为空时，默认为当前时间开始计算
 */


function getEpochTime(time) {
  if (time === undefined) {
    time = new Date().getTime();
  }

  const d = beginEpochTime();
  const t = d.getTime();
  return Math.floor((time - t) / 1000);
}

function getTime(time) {
  return getEpochTime(time);
}

function getRealTime(epochTime) {
  if (epochTime === undefined) {
    epochTime = getTime();
  }

  const d = beginEpochTime();
  const t = Math.floor(d.getTime() / 1000) * 1000;
  return t + epochTime * 1000;
}

function getSlotNumber(epochTime) {
  if (epochTime === undefined) {
    epochTime = getTime();
  }

  return Math.floor(epochTime / interval);
}

function getSlotTime(slot) {
  return slot * interval;
}

function getNextSlot() {
  const slot = getSlotNumber();
  return slot + 1;
}

function getLastSlot(nextSlot) {
  return nextSlot + delegates;
}

var _default = {
  interval,
  delegates,
  getTime,
  getRealTime,
  getSlotNumber,
  getSlotTime,
  getNextSlot,
  getLastSlot,
  beginEpochTime
};
exports.default = _default;