index.js 1.4 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = addMilliseconds;
  7. var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
  8. var _index2 = _interopRequireDefault(require("../toDate/index.js"));
  9. var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  10. /**
  11. * @name addMilliseconds
  12. * @category Millisecond Helpers
  13. * @summary Add the specified number of milliseconds to the given date.
  14. *
  15. * @description
  16. * Add the specified number of milliseconds to the given date.
  17. *
  18. * @param {Date|Number} date - the date to be changed
  19. * @param {Number} amount - the amount of milliseconds to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
  20. * @returns {Date} the new date with the milliseconds added
  21. * @throws {TypeError} 2 arguments required
  22. *
  23. * @example
  24. * // Add 750 milliseconds to 10 July 2014 12:45:30.000:
  25. * const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
  26. * //=> Thu Jul 10 2014 12:45:30.750
  27. */
  28. function addMilliseconds(dirtyDate, dirtyAmount) {
  29. (0, _index3.default)(2, arguments);
  30. var timestamp = (0, _index2.default)(dirtyDate).getTime();
  31. var amount = (0, _index.default)(dirtyAmount);
  32. return new Date(timestamp + amount);
  33. }
  34. module.exports = exports.default;