Analyze leap year calculations, calendar systems, and date validation logic. Use this when the user asks about leap year rules, calendar types (Gregorian, Julian, Hebrew, Chinese), year range validation (1582-9999), mathematical formulas, or needs to understand the core leap year detection algorithms.
This Skill helps analyze and understand the leap year calculation logic used in the IsLeapYear application.
Located in src/utils/leap-year.ts
The standard leap year rule used globally since 1582:
(year % 4 === 0 && year % 100 !== 0) || year % 400 === 0
Rules:
Valid Range: 1582-9999 (Gregorian calendar introduction to far future)
Examples:
Simpler rule used before Gregorian calendar:
year % 4 === 0
Rule: Any year divisible by 4 is a leap year (no century exception)
Uses Metonic cycle approximation (19-year cycle with 7 leap years):
[3, 6, 8, 11, 14, 17, 19].includes((year % 19) + 1)
Leap years occur in years: 3, 6, 8, 11, 14, 17, 19 of each 19-year cycle
Also uses Metonic cycle approximation:
[3, 5, 8, 11, 13, 16, 19].includes((year % 19) + 1)
Leap years occur in years: 3, 5, 8, 11, 13, 16, 19 of each 19-year cycle
type CalendarType = "gregorian" | "julian" | "hebrew" | "chinese";
Pope Gregory XIII introduced the Gregorian calendar in October 1582 to correct drift in the Julian calendar. The app validates Gregorian dates starting from this year to maintain historical accuracy.
if (Number.isNaN(year)) {
return errorResponse("Invalid year parameter");
}
if (year < 1582 || year > 9999) {
return errorResponse("Year must be between 1582 and 9999");
}
Use the functions from src/utils/leap-year.ts:
isLeapYear(year: number, calendar?: CalendarType): booleanimport { isLeapYear } from "@/utils/leap-year"Iterate through range and count:
const leapYears = [];
for (let y = start; y <= end; y++) {
if (isLeapYear(y, calendar)) {
leapYears.push(y);
}
}
Only 1 in 4 century years is a leap year in Gregorian:
# Current year (2025 - not a leap year)
curl http://localhost:3000/api/check
# Standard leap year
curl http://localhost:3000/api/check/2024
# Century leap year
curl http://localhost:3000/api/check/2000
# Century non-leap year
curl http://localhost:3000/api/check/1900
# Julian vs Gregorian comparison
curl http://localhost:3000/api/calendar/julian/check/1900
curl http://localhost:3000/api/calendar/gregorian/check/1900
# Batch test edge cases
curl -X POST http://localhost:3000/api/check/batch \
-H "Content-Type: application/json" \
-d '{"years": [1900, 2000, 2024, 2100, 2400]}'
src/utils/leap-year.ts and used across API routes