UNPKG

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