UNPKG

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