isLeapYear.js 809 B

12345678910111213141516171819202122232425262728
  1. "use strict";
  2. exports.isLeapYear = isLeapYear;
  3. var _index = require("./toDate.js");
  4. /**
  5. * @name isLeapYear
  6. * @category Year Helpers
  7. * @summary Is the given date in the leap year?
  8. *
  9. * @description
  10. * Is the given date in the leap year?
  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 the leap year
  17. *
  18. * @example
  19. * // Is 1 September 2012 in the leap year?
  20. * const result = isLeapYear(new Date(2012, 8, 1))
  21. * //=> true
  22. */
  23. function isLeapYear(date) {
  24. const _date = (0, _index.toDate)(date);
  25. const year = _date.getFullYear();
  26. return year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0);
  27. }