index.js 894 B

1234567891011121314151617181920212223242526
  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. * @param {Date|Number} dateLeft - the first date to check
  12. * @param {Date|Number} dateRight - the second date to check
  13. * @returns {Boolean} the dates are in the same year
  14. * @throws {TypeError} 2 arguments required
  15. *
  16. * @example
  17. * // Are 2 September 2014 and 25 September 2014 in the same year?
  18. * const result = isSameYear(new Date(2014, 8, 2), new Date(2014, 8, 25))
  19. * //=> true
  20. */
  21. export default function isSameYear(dirtyDateLeft, dirtyDateRight) {
  22. requiredArgs(2, arguments);
  23. var dateLeft = toDate(dirtyDateLeft);
  24. var dateRight = toDate(dirtyDateRight);
  25. return dateLeft.getFullYear() === dateRight.getFullYear();
  26. }