index.js 1.1 KB

12345678910111213141516171819202122232425262728
  1. import toInteger from "../_lib/toInteger/index.js";
  2. import addMilliseconds from "../addMilliseconds/index.js";
  3. import requiredArgs from "../_lib/requiredArgs/index.js";
  4. var MILLISECONDS_IN_MINUTE = 60000;
  5. /**
  6. * @name addMinutes
  7. * @category Minute Helpers
  8. * @summary Add the specified number of minutes to the given date.
  9. *
  10. * @description
  11. * Add the specified number of minutes to the given date.
  12. *
  13. * @param {Date|Number} date - the date to be changed
  14. * @param {Number} amount - the amount of minutes to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
  15. * @returns {Date} the new date with the minutes added
  16. * @throws {TypeError} 2 arguments required
  17. *
  18. * @example
  19. * // Add 30 minutes to 10 July 2014 12:00:00:
  20. * const result = addMinutes(new Date(2014, 6, 10, 12, 0), 30)
  21. * //=> Thu Jul 10 2014 12:30:00
  22. */
  23. export default function addMinutes(dirtyDate, dirtyAmount) {
  24. requiredArgs(2, arguments);
  25. var amount = toInteger(dirtyAmount);
  26. return addMilliseconds(dirtyDate, amount * MILLISECONDS_IN_MINUTE);
  27. }