isLeapYear.cjs 687 B

123456789101112131415161718192021222324252627
  1. "use strict";
  2. exports.isLeapYear = isLeapYear;
  3. var _index = require("./toDate.cjs");
  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. * @param date - The date to check
  13. * @param options - The options object
  14. *
  15. * @returns The date is in the leap year
  16. *
  17. * @example
  18. * // Is 1 September 2012 in the leap year?
  19. * const result = isLeapYear(new Date(2012, 8, 1))
  20. * //=> true
  21. */
  22. function isLeapYear(date, options) {
  23. const _date = (0, _index.toDate)(date, options?.in);
  24. const year = _date.getFullYear();
  25. return year % 400 === 0 || (year % 4 === 0 && year % 100 !== 0);
  26. }