You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

33 lines
1.1 KiB

  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. * ### v2.0.0 breaking changes:
  13. *
  14. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  15. *
  16. * @param {Date|Number} date - the date to be changed
  17. * @param {Number} milliseconds - the milliseconds of the new date
  18. * @returns {Date} the new date with the milliseconds set
  19. * @throws {TypeError} 2 arguments required
  20. *
  21. * @example
  22. * // Set 300 milliseconds to 1 September 2014 11:30:40.500:
  23. * var result = setMilliseconds(new Date(2014, 8, 1, 11, 30, 40, 500), 300)
  24. * //=> Mon Sep 01 2014 11:30:40.300
  25. */
  26. export default function setMilliseconds(dirtyDate, dirtyMilliseconds) {
  27. requiredArgs(2, arguments);
  28. var date = toDate(dirtyDate);
  29. var milliseconds = toInteger(dirtyMilliseconds);
  30. date.setMilliseconds(milliseconds);
  31. return date;
  32. }