monthsToQuarters.js 748 B

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