isSameMonth.cjs 1.2 KB

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