getQuarter.cjs 696 B

12345678910111213141516171819202122232425262728293031
  1. "use strict";
  2. exports.getQuarter = getQuarter;
  3. var _index = require("./toDate.cjs");
  4. /**
  5. * The {@link getQuarter} function options.
  6. */
  7. /**
  8. * @name getQuarter
  9. * @category Quarter Helpers
  10. * @summary Get the year quarter of the given date.
  11. *
  12. * @description
  13. * Get the year quarter of the given date.
  14. *
  15. * @param date - The given date
  16. * @param options - An object with options
  17. *
  18. * @returns The quarter
  19. *
  20. * @example
  21. * // Which quarter is 2 July 2014?
  22. * const result = getQuarter(new Date(2014, 6, 2));
  23. * //=> 3
  24. */
  25. function getQuarter(date, options) {
  26. const _date = (0, _index.toDate)(date, options?.in);
  27. const quarter = Math.trunc(_date.getMonth() / 3) + 1;
  28. return quarter;
  29. }