isLeapYear.js 700 B

12345678910111213141516171819202122232425262728
  1. import { toDate } from "./toDate.js";
  2. /**
  3. * @name isLeapYear
  4. * @category Year Helpers
  5. * @summary Is the given date in the leap year?
  6. *
  7. * @description
  8. * Is the given date in the leap year?
  9. *
  10. * @param date - The date to check
  11. * @param options - The options object
  12. *
  13. * @returns The date is in the leap year
  14. *
  15. * @example
  16. * // Is 1 September 2012 in the leap year?
  17. * const result = isLeapYear(new Date(2012, 8, 1))
  18. * //=> true
  19. */
  20. export function isLeapYear(date, options) {
  21. const _date = toDate(date, options?.in);
  22. const year = _date.getFullYear();
  23. return year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0);
  24. }
  25. // Fallback for modularized imports:
  26. export default isLeapYear;