Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

32 lignes
1.3 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 addMilliseconds
  6. * @category Millisecond Helpers
  7. * @summary Add the specified number of milliseconds to the given date.
  8. *
  9. * @description
  10. * Add the specified number of 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} 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`.
  18. * @returns {Date} the new date with the milliseconds added
  19. * @throws {TypeError} 2 arguments required
  20. *
  21. * @example
  22. * // Add 750 milliseconds to 10 July 2014 12:45:30.000:
  23. * var result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
  24. * //=> Thu Jul 10 2014 12:45:30.750
  25. */
  26. export default function addMilliseconds(dirtyDate, dirtyAmount) {
  27. requiredArgs(2, arguments);
  28. var timestamp = toDate(dirtyDate).getTime();
  29. var amount = toInteger(dirtyAmount);
  30. return new Date(timestamp + amount);
  31. }