"use strict"; // Pure Gregorian leap-year rule (Gregorian calendar reform of 1582, as codified in modern // reference works, cited below). No day-number conversion is needed for this method, no host // clock, no Date.now(). function isLeapGregorian(y) { return (y % 4 === 0 && y % 100 !== 0) || (y % 400 === 0); } module.exports = { slug: "is-leap-year", title: "Is it a leap year?", deck_category: "dates", description: "Determines whether a given year is a leap year under the Gregorian calendar rule.", inputs: [ { name: "year", type: "integer", required: true, description: "Proleptic Gregorian calendar year" } ], outputs: [ { name: "is_leap", type: "boolean", description: "True if the year has a February 29" } ], steps: [ "A year is a leap year if it is divisible by 4.", "Exception: a year divisible by 100 is NOT a leap year.", "Exception to the exception: a year divisible by 400 IS a leap year.", "Apply the rules in that order (or equivalently: divisible by 4 and not by 100, OR divisible by 400)." ], constants: [], sources: [ { kind: "url", value: "https://aa.usno.navy.mil/faq/calendars", title: "Calendars FAQ", publisher: "US Naval Observatory / Astronomical Applications Department", retrieved_utc: "2026-09-30T19:41:35Z", note: "states the Gregorian leap-year rule: divisible by 4, except centuries, unless divisible by 400" } ], disclaimer: null, questionText(inputs) { return "Is " + inputs.year + " a leap year?"; }, run(inputs) { if (!Number.isInteger(inputs.year)) throw new Error("year must be an integer"); const isLeap = isLeapGregorian(inputs.year); return { answer: isLeap ? "yes" : "no", values: { is_leap: isLeap } }; }, examples: [ { name: "worked example", inputs: { year: 2000 }, expected: { answer: "yes" }, check: "2000 is divisible by 400, so it is a leap year despite being a century year" }, { name: "test vector: century exception", inputs: { year: 1900 }, expected: { answer: "no" }, check: "1900 is divisible by 100 but not by 400, so it is not a leap year" }, { name: "test vector: ordinary leap year", inputs: { year: 2024 }, expected: { answer: "yes" }, check: "2024 is divisible by 4 and not by 100" } ] };