isSameYear.js 935 B

123456789101112131415161718192021222324252627282930313233343536
  1. import { normalizeDates } from "./_lib/normalizeDates.js";
  2. /**
  3. * The {@link isSameYear} function options.
  4. */
  5. /**
  6. * @name isSameYear
  7. * @category Year Helpers
  8. * @summary Are the given dates in the same year?
  9. *
  10. * @description
  11. * Are the given dates in the same year?
  12. *
  13. * @param laterDate - The first date to check
  14. * @param earlierDate - The second date to check
  15. * @param options - An object with options
  16. *
  17. * @returns The dates are in the same year
  18. *
  19. * @example
  20. * // Are 2 September 2014 and 25 September 2014 in the same year?
  21. * const result = isSameYear(new Date(2014, 8, 2), new Date(2014, 8, 25))
  22. * //=> true
  23. */
  24. export function isSameYear(laterDate, earlierDate, options) {
  25. const [laterDate_, earlierDate_] = normalizeDates(
  26. options?.in,
  27. laterDate,
  28. earlierDate,
  29. );
  30. return laterDate_.getFullYear() === earlierDate_.getFullYear();
  31. }
  32. // Fallback for modularized imports:
  33. export default isSameYear;