index.js 1.1 KB

12345678910111213141516171819202122232425262728293031
  1. import startOfQuarter from "../startOfQuarter/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isSameQuarter
  5. * @category Quarter Helpers
  6. * @summary Are the given dates in the same year quarter?
  7. *
  8. * @description
  9. * Are the given dates in the same year quarter?
  10. *
  11. * ### v2.0.0 breaking changes:
  12. *
  13. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  14. *
  15. * @param {Date|Number} dateLeft - the first date to check
  16. * @param {Date|Number} dateRight - the second date to check
  17. * @returns {Boolean} the dates are in the same quarter
  18. * @throws {TypeError} 2 arguments required
  19. *
  20. * @example
  21. * // Are 1 January 2014 and 8 March 2014 in the same quarter?
  22. * var result = isSameQuarter(new Date(2014, 0, 1), new Date(2014, 2, 8))
  23. * //=> true
  24. */
  25. export default function isSameQuarter(dirtyDateLeft, dirtyDateRight) {
  26. requiredArgs(2, arguments);
  27. var dateLeftStartOfQuarter = startOfQuarter(dirtyDateLeft);
  28. var dateRightStartOfQuarter = startOfQuarter(dirtyDateRight);
  29. return dateLeftStartOfQuarter.getTime() === dateRightStartOfQuarter.getTime();
  30. }