Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 
 

32 linhas
1.2 KiB

  1. import toInteger from '../_lib/toInteger/index.js';
  2. import addMonths from '../addMonths/index.js';
  3. import requiredArgs from '../_lib/requiredArgs/index.js';
  4. /**
  5. * @name addQuarters
  6. * @category Quarter Helpers
  7. * @summary Add the specified number of year quarters to the given date.
  8. *
  9. * @description
  10. * Add the specified number of year quarters to the given date.
  11. *
  12. * ### v2.0.0 breaking changes:
  13. *
  14. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  15. *
  16. * @param {Date|Number} date - the date to be changed
  17. * @param {Number} amount - the amount of quarters to be added. Positive decimals will be rounded using `Math.floor`, decimals less than zero will be rounded using `Math.ceil`.
  18. * @returns {Date} the new date with the quarters added
  19. * @throws {TypeError} 2 arguments required
  20. *
  21. * @example
  22. * // Add 1 quarter to 1 September 2014:
  23. * var result = addQuarters(new Date(2014, 8, 1), 1)
  24. * //=> Mon Dec 01 2014 00:00:00
  25. */
  26. export default function addQuarters(dirtyDate, dirtyAmount) {
  27. requiredArgs(2, arguments);
  28. var amount = toInteger(dirtyAmount);
  29. var months = amount * 3;
  30. return addMonths(dirtyDate, months);
  31. }