quartersToMonths.mjs 817 B

123456789101112131415161718192021222324252627
  1. import { monthsInQuarter } from "./constants.mjs";
  2. /**
  3. * @name quartersToMonths
  4. * @category Conversion Helpers
  5. * @summary Convert number of quarters to months.
  6. *
  7. * @description
  8. * Convert a number of quarters to a full number of months.
  9. *
  10. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  11. *
  12. * @param quarters - The number of quarters to be converted
  13. *
  14. * @returns The number of quarters converted in months
  15. *
  16. * @example
  17. * // Convert 2 quarters to months
  18. * const result = quartersToMonths(2)
  19. * //=> 6
  20. */
  21. export function quartersToMonths(quarters) {
  22. return Math.trunc(quarters * monthsInQuarter);
  23. }
  24. // Fallback for modularized imports:
  25. export default quartersToMonths;