addMilliseconds.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435
  1. import { constructFrom } from "./constructFrom.js";
  2. import { toDate } from "./toDate.js";
  3. /**
  4. * The {@link addMilliseconds} function options.
  5. */
  6. /**
  7. * @name addMilliseconds
  8. * @category Millisecond Helpers
  9. * @summary Add the specified number of milliseconds to the given date.
  10. *
  11. * @description
  12. * Add the specified number of milliseconds to the given date.
  13. *
  14. * @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).
  15. * @typeParam ResultDate - The result `Date` type, it is the type returned from the context function if it is passed, or inferred from the arguments.
  16. *
  17. * @param date - The date to be changed
  18. * @param amount - The amount of milliseconds to be added.
  19. * @param options - The options object
  20. *
  21. * @returns The new date with the milliseconds added
  22. *
  23. * @example
  24. * // Add 750 milliseconds to 10 July 2014 12:45:30.000:
  25. * const result = addMilliseconds(new Date(2014, 6, 10, 12, 45, 30, 0), 750)
  26. * //=> Thu Jul 10 2014 12:45:30.750
  27. */
  28. export function addMilliseconds(date, amount, options) {
  29. return constructFrom(options?.in || date, +toDate(date) + amount);
  30. }
  31. // Fallback for modularized imports:
  32. export default addMilliseconds;