index.js 833 B

123456789101112131415161718192021222324252627282930
  1. import requiredArgs from "../_lib/requiredArgs/index.js";
  2. import { monthsInQuarter } from "../constants/index.js";
  3. /**
  4. * @name monthsToQuarters
  5. * @category Conversion Helpers
  6. * @summary Convert number of months to quarters.
  7. *
  8. * @description
  9. * Convert a number of months to a full number of quarters.
  10. *
  11. * @param {number} months - number of months to be converted.
  12. *
  13. * @returns {number} the number of months converted in quarters
  14. * @throws {TypeError} 1 argument required
  15. *
  16. * @example
  17. * // Convert 6 months to quarters:
  18. * const result = monthsToQuarters(6)
  19. * //=> 2
  20. *
  21. * @example
  22. * // It uses floor rounding:
  23. * const result = monthsToQuarters(7)
  24. * //=> 2
  25. */
  26. export default function monthsToQuarters(months) {
  27. requiredArgs(1, arguments);
  28. var quarters = months / monthsInQuarter;
  29. return Math.floor(quarters);
  30. }