addMilliseconds.cjs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. exports.addMilliseconds = addMilliseconds;
  3. var _index = require("./constructFrom.cjs");
  4. var _index2 = require("./toDate.cjs");
  5. /**
  6. * The {@link addMilliseconds} function options.
  7. */
  8. /**
  9. * @name addMilliseconds
  10. * @category Millisecond Helpers
  11. * @summary Add the specified number of milliseconds to the given date.
  12. *
  13. * @description
  14. * Add the specified number of milliseconds to the given date.
  15. *
  16. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  17. * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
  18. *
  19. * @param date - The date to be changed
  20. * @param amount - The amount of milliseconds to be added.
  21. * @param options - The options object
  22. *
  23. * @returns The new date with the milliseconds added
  24. *
  25. * @example
  26. * // Add 750 milliseconds to 10 July 2014 12:45:30.000:
  27. * const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
  28. * //=> Thu Jul 10 2014 12:45:30.750
  29. */
  30. function addMilliseconds(date, amount, options) {
  31. return (0, _index.constructFrom)(
  32. options?.in || date,
  33. +(0, _index2.toDate)(date) + amount,
  34. );
  35. }