isLeapYear.js 624 B

1234567891011121314151617181920212223
  1. import DeveloperError from "./DeveloperError.js";
  2. /**
  3. * Determines if a given date is a leap year.
  4. *
  5. * @function isLeapYear
  6. *
  7. * @param {Number} year The year to be tested.
  8. * @returns {Boolean} True if <code>year</code> is a leap year.
  9. *
  10. * @example
  11. * const leapYear = Cesium.isLeapYear(2000); // true
  12. */
  13. function isLeapYear(year) {
  14. //>>includeStart('debug', pragmas.debug);
  15. if (year === null || isNaN(year)) {
  16. throw new DeveloperError("year is required and must be a number.");
  17. }
  18. //>>includeEnd('debug');
  19. return (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0;
  20. }
  21. export default isLeapYear;