isSameYear.mjs 956 B

123456789101112131415161718192021222324252627282930
  1. import { toDate } from "./toDate.mjs";
  2. /**
  3. * @name isSameYear
  4. * @category Year Helpers
  5. * @summary Are the given dates in the same year?
  6. *
  7. * @description
  8. * Are the given dates in the same year?
  9. *
  10. * @typeParam DateType - The `Date` type, the function operates on. Gets inferred from passed arguments. Allows to use extensions like [`UTCDate`](https://github.com/date-fns/utc).
  11. *
  12. * @param dateLeft - The first date to check
  13. * @param dateRight - The second date to check
  14. *
  15. * @returns The dates are in the same year
  16. *
  17. * @example
  18. * // Are 2 September 2014 and 25 September 2014 in the same year?
  19. * const result = isSameYear(new Date(2014, 8, 2), new Date(2014, 8, 25))
  20. * //=> true
  21. */
  22. export function isSameYear(dateLeft, dateRight) {
  23. const _dateLeft = toDate(dateLeft);
  24. const _dateRight = toDate(dateRight);
  25. return _dateLeft.getFullYear() === _dateRight.getFullYear();
  26. }
  27. // Fallback for modularized imports:
  28. export default isSameYear;