index.js 895 B

123456789101112131415161718192021222324252627
  1. import isSameYear from "../isSameYear/index.js";
  2. import requiredArgs from "../_lib/requiredArgs/index.js";
  3. /**
  4. * @name isThisYear
  5. * @category Year Helpers
  6. * @summary Is the given date in the same year as the current date?
  7. * @pure false
  8. *
  9. * @description
  10. * Is the given date in the same year as the current date?
  11. *
  12. * > ⚠️ Please note that this function is not present in the FP submodule as
  13. * > it uses `Date.now()` internally hence impure and can't be safely curried.
  14. *
  15. * @param {Date|Number} date - the date to check
  16. * @returns {Boolean} the date is in this year
  17. * @throws {TypeError} 1 argument required
  18. *
  19. * @example
  20. * // If today is 25 September 2014, is 2 July 2014 in this year?
  21. * const result = isThisYear(new Date(2014, 6, 2))
  22. * //=> true
  23. */
  24. export default function isThisYear(dirtyDate) {
  25. requiredArgs(1, arguments);
  26. return isSameYear(dirtyDate, Date.now());
  27. }