index.js 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. "use strict";
  2. var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
  3. Object.defineProperty(exports, "__esModule", {
  4. value: true
  5. });
  6. exports.default = monthsToYears;
  7. var _index = _interopRequireDefault(require("../_lib/requiredArgs/index.js"));
  8. var _index2 = require("../constants/index.js");
  9. /**
  10. * @name monthsToYears
  11. * @category Conversion Helpers
  12. * @summary Convert number of months to years.
  13. *
  14. * @description
  15. * Convert a number of months to a full number of years.
  16. *
  17. * @param {number} months - number of months to be converted
  18. *
  19. * @returns {number} the number of months converted in years
  20. * @throws {TypeError} 1 argument required
  21. *
  22. * @example
  23. * // Convert 36 months to years:
  24. * const result = monthsToYears(36)
  25. * //=> 3
  26. *
  27. * // It uses floor rounding:
  28. * const result = monthsToYears(40)
  29. * //=> 3
  30. */
  31. function monthsToYears(months) {
  32. (0, _index.default)(1, arguments);
  33. var years = months / _index2.monthsInYear;
  34. return Math.floor(years);
  35. }
  36. module.exports = exports.default;