"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.fromDuration = fromDuration;
exports.fromTimestamp = fromTimestamp;
exports.numberToLong = numberToLong;
exports.toDuration = toDuration;
exports.toTimestamp = toTimestamp;
var _long = _interopRequireDefault(require("long"));
/**
 * @param duration nanoseconds
 */
function toDuration(duration) {
  return {
    seconds: _long["default"].fromNumber(Math.floor(parseInt(duration) / 1000000000)),
    nanos: parseInt(duration) % 1000000000
  };
}

/**
 * @return nanoseconds
 */
function fromDuration(duration) {
  return (parseInt(duration.seconds.toString()) * 1000000000 + duration.nanos).toString();
}
function toTimestamp(date) {
  var seconds = numberToLong(date.getTime() / 1000);
  var nanos = date.getTime() % 1000 * 1000000;
  return {
    seconds: seconds,
    nanos: nanos
  };
}
function fromTimestamp(t) {
  var millis = t.seconds.toNumber() * 1000;
  millis += t.nanos / 1000000;
  return new Date(millis);
}
function numberToLong(number) {
  return _long["default"].fromNumber(number);
}