You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

31 lines
1.0 KiB

  1. import toDate from '../toDate/index.js';
  2. import requiredArgs from '../_lib/requiredArgs/index.js';
  3. /**
  4. * @name isSameYear
  5. * @category Year Helpers
  6. * @summary Are the given dates in the same year?
  7. *
  8. * @description
  9. * Are the given dates in the same year?
  10. *
  11. * ### v2.0.0 breaking changes:
  12. *
  13. * - [Changes that are common for the whole library](https://github.com/date-fns/date-fns/blob/master/docs/upgradeGuide.md#Common-Changes).
  14. *
  15. * @param {Date|Number} dateLeft - the first date to check
  16. * @param {Date|Number} dateRight - the second date to check
  17. * @returns {Boolean} the dates are in the same year
  18. * @throws {TypeError} 2 arguments required
  19. *
  20. * @example
  21. * // Are 2 September 2014 and 25 September 2014 in the same year?
  22. * var result = isSameYear(new Date(2014, 8, 2), new Date(2014, 8, 25))
  23. * //=> true
  24. */
  25. export default function isSameYear(dirtyDateLeft, dirtyDateRight) {
  26. requiredArgs(2, arguments);
  27. var dateLeft = toDate(dirtyDateLeft);
  28. var dateRight = toDate(dirtyDateRight);
  29. return dateLeft.getFullYear() === dateRight.getFullYear();
  30. }