isThisYear.mjs 870 B

1234567891011121314151617181920212223242526272829
  1. import { constructNow } from "./constructNow.mjs";
  2. import { isSameYear } from "./isSameYear.mjs";
  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. * @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 date - The date to check
  15. *
  16. * @returns The date is in this year
  17. *
  18. * @example
  19. * // If today is 25 September 2014, is 2 July 2014 in this year?
  20. * const result = isThisYear(new Date(2014, 6, 2))
  21. * //=> true
  22. */
  23. export function isThisYear(date) {
  24. return isSameYear(date, constructNow(date));
  25. }
  26. // Fallback for modularized imports:
  27. export default isThisYear;