addMinutes.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import { millisecondsInMinute } from "./constants.js";
  2. import { toDate } from "./toDate.js";
  3. /**
  4. * The {@link addMinutes} function options.
  5. */
  6. /**
  7. * @name addMinutes
  8. * @category Minute Helpers
  9. * @summary Add the specified number of minutes to the given date.
  10. *
  11. * @description
  12. * Add the specified number of minutes 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 minutes to be added.
  19. * @param options - An object with options
  20. *
  21. * @returns The new date with the minutes added
  22. *
  23. * @example
  24. * // Add 30 minutes to 10 July 2014 12:00:00:
  25. * const result = addMinutes(new Date(2014, 6, 10, 12, 0), 30)
  26. * //=> Thu Jul 10 2014 12:30:00
  27. */
  28. export function addMinutes(date, amount, options) {
  29. const _date = toDate(date, options?.in);
  30. _date.setTime(_date.getTime() + amount * millisecondsInMinute);
  31. return _date;
  32. }
  33. // Fallback for modularized imports:
  34. export default addMinutes;