addMinutes.cjs 1.2 KB

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