index.js 1.2 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 quarter (and year)?
  7. *
  8. * @description
  9. * Are the given dates in the same quarter (and year)?
  10. *
  11. * @param {Date|Number} dateLeft - the first date to check
  12. * @param {Date|Number} dateRight - the second date to check
  13. * @returns {Boolean} the dates are in the same quarter (and year)
  14. * @throws {TypeError} 2 arguments required
  15. *
  16. * @example
  17. * // Are 1 January 2014 and 8 March 2014 in the same quarter?
  18. * const result = isSameQuarter(new Date(2014, 0, 1), new Date(2014, 2, 8))
  19. * //=> true
  20. *
  21. * @example
  22. * // Are 1 January 2014 and 1 January 2015 in the same quarter?
  23. * const result = isSameQuarter(new Date(2014, 0, 1), new Date(2015, 0, 1))
  24. * //=> false
  25. */
  26. export default function isSameQuarter(dirtyDateLeft, dirtyDateRight) {
  27. requiredArgs(2, arguments);
  28. var dateLeftStartOfQuarter = startOfQuarter(dirtyDateLeft);
  29. var dateRightStartOfQuarter = startOfQuarter(dirtyDateRight);
  30. return dateLeftStartOfQuarter.getTime() === dateRightStartOfQuarter.getTime();
  31. }