isSameQuarter.js 1.2 KB

1234567891011121314151617181920212223242526272829303132333435
  1. "use strict";
  2. exports.isSameQuarter = isSameQuarter;
  3. var _index = require("./startOfQuarter.js");
  4. /**
  5. * @name isSameQuarter
  6. * @category Quarter Helpers
  7. * @summary Are the given dates in the same quarter (and year)?
  8. *
  9. * @description
  10. * Are the given dates in the same quarter (and year)?
  11. *
  12. * @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).
  13. *
  14. * @param dateLeft - The first date to check
  15. * @param dateRight - The second date to check
  16. * @returns The dates are in the same quarter (and year)
  17. *
  18. * @example
  19. * // Are 1 January 2014 and 8 March 2014 in the same quarter?
  20. * const result = isSameQuarter(new Date(2014, 0, 1), new Date(2014, 2, 8))
  21. * //=> true
  22. *
  23. * @example
  24. * // Are 1 January 2014 and 1 January 2015 in the same quarter?
  25. * const result = isSameQuarter(new Date(2014, 0, 1), new Date(2015, 0, 1))
  26. * //=> false
  27. */
  28. function isSameQuarter(dateLeft, dateRight) {
  29. const dateLeftStartOfQuarter = (0, _index.startOfQuarter)(dateLeft);
  30. const dateRightStartOfQuarter = (0, _index.startOfQuarter)(dateRight);
  31. return +dateLeftStartOfQuarter === +dateRightStartOfQuarter;
  32. }