isSameQuarter.cjs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. "use strict";
  2. exports.isSameQuarter = isSameQuarter;
  3. var _index = require("./_lib/normalizeDates.cjs");
  4. var _index2 = require("./startOfQuarter.cjs");
  5. /**
  6. * The {@link isSameQuarter} function options.
  7. */
  8. /**
  9. * @name isSameQuarter
  10. * @category Quarter Helpers
  11. * @summary Are the given dates in the same quarter (and year)?
  12. *
  13. * @description
  14. * Are the given dates in the same quarter (and year)?
  15. *
  16. * @param laterDate - The first date to check
  17. * @param earlierDate - The second date to check
  18. * @param options - An object with options
  19. *
  20. * @returns The dates are in the same quarter (and year)
  21. *
  22. * @example
  23. * // Are 1 January 2014 and 8 March 2014 in the same quarter?
  24. * const result = isSameQuarter(new Date(2014, 0, 1), new Date(2014, 2, 8))
  25. * //=> true
  26. *
  27. * @example
  28. * // Are 1 January 2014 and 1 January 2015 in the same quarter?
  29. * const result = isSameQuarter(new Date(2014, 0, 1), new Date(2015, 0, 1))
  30. * //=> false
  31. */
  32. function isSameQuarter(laterDate, earlierDate, options) {
  33. const [dateLeft_, dateRight_] = (0, _index.normalizeDates)(
  34. options?.in,
  35. laterDate,
  36. earlierDate,
  37. );
  38. return (
  39. +(0, _index2.startOfQuarter)(dateLeft_) ===
  40. +(0, _index2.startOfQuarter)(dateRight_)
  41. );
  42. }