isSameYear.js 953 B

1234567891011121314151617181920212223242526272829
  1. "use strict";
  2. exports.isSameYear = isSameYear;
  3. var _index = require("./toDate.js");
  4. /**
  5. * @name isSameYear
  6. * @category Year Helpers
  7. * @summary Are the given dates in the same year?
  8. *
  9. * @description
  10. * Are the given dates in the same year?
  11. *
  12. * @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).
  13. *
  14. * @param dateLeft - The first date to check
  15. * @param dateRight - The second date to check
  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. function isSameYear(dateLeft, dateRight) {
  25. const _dateLeft = (0, _index.toDate)(dateLeft);
  26. const _dateRight = (0, _index.toDate)(dateRight);
  27. return _dateLeft.getFullYear() === _dateRight.getFullYear();
  28. }