UNPKG

699 BJavaScriptView Raw
1import { monthsInYear } from "./constants.js";
2
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 months - The number of months to be converted
12 *
13 * @returns The number of months converted in years
14 *
15 * @example
16 * // Convert 36 months to years:
17 * const result = monthsToYears(36)
18 * //=> 3
19 *
20 * // It uses floor rounding:
21 * const result = monthsToYears(40)
22 * //=> 3
23 */
24export function monthsToYears(months) {
25 const years = months / monthsInYear;
26 return Math.trunc(years);
27}
28
29// Fallback for modularized imports:
30export default monthsToYears;