index.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = setMilliseconds;
  6. var _index = _interopRequireDefault(require("../_lib/toInteger/index.js"));
  7. var _index2 = _interopRequireDefault(require("../toDate/index.js"));
  8. var _index3 = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. /**
  11. * @name setMilliseconds
  12. * @category Millisecond Helpers
  13. * @summary Set the milliseconds to the given date.
  14. *
  15. * @description
  16. * Set the milliseconds to the given date.
  17. *
  18. * ### v2.0.0 breaking changes:
  19. *
  20. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  21. *
  22. * @param {Date|Number} date - the date to be changed
  23. * @param {Number} milliseconds - the milliseconds of the new date
  24. * @returns {Date} the new date with the milliseconds set
  25. * @throws {TypeError} 2 arguments required
  26. *
  27. * @example
  28. * // Set 300 milliseconds to 1 September 2014 11:30:40.500:
  29. * const result = setMilliseconds(new Date(2014, 8, 1, 11, 30, 40, 500), 300)
  30. * //=> Mon Sep 01 2014 11:30:40.300
  31. */
  32. function setMilliseconds(dirtyDate, dirtyMilliseconds) {
  33. (0, _index3.default)(2, arguments);
  34. var date = (0, _index2.default)(dirtyDate);
  35. var milliseconds = (0, _index.default)(dirtyMilliseconds);
  36. date.setMilliseconds(milliseconds);
  37. return date;
  38. }
  39. module.exports = exports.default;