index.js 987 B

12345678910111213141516171819202122232425262728
  1. import toInteger from "../_lib/toInteger/index.js";
  2. import toDate from "../toDate/index.js";
  3. import requiredArgs from "../_lib/requiredArgs/index.js";
  4. /**
  5. * @name setMilliseconds
  6. * @category Millisecond Helpers
  7. * @summary Set the milliseconds to the given date.
  8. *
  9. * @description
  10. * Set the milliseconds to the given date.
  11. *
  12. * @param {Date|Number} date - the date to be changed
  13. * @param {Number} milliseconds - the milliseconds of the new date
  14. * @returns {Date} the new date with the milliseconds set
  15. * @throws {TypeError} 2 arguments required
  16. *
  17. * @example
  18. * // Set 300 milliseconds to 1 September 2014 11:30:40.500:
  19. * const result = setMilliseconds(new Date(2014, 8, 1, 11, 30, 40, 500), 300)
  20. * //=> Mon Sep 01 2014 11:30:40.300
  21. */
  22. export default function setMilliseconds(dirtyDate, dirtyMilliseconds) {
  23. requiredArgs(2, arguments);
  24. var date = toDate(dirtyDate);
  25. var milliseconds = toInteger(dirtyMilliseconds);
  26. date.setMilliseconds(milliseconds);
  27. return date;
  28. }