addSeconds.js 1.1 KB

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