index.js 787 B

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