Check Leap Year
Check if a year is a leap year.
isLeapYear
Checks if a given year is a leap year according to the Gregorian calendar rules.
Leap Year Rules
-
A year is a leap year if it is divisible by 4.
-
However, years divisible by 100 are not leap years unless they are also divisible by 400.
-
For example:
2000,2020,2400→ leap years ✅1900,2100→ not leap years ❌
Function Signature
function isLeapYear(year: Numeric): boolean;Parameters
year: The year to check (can be number or numeric string)
Returns
true if the year is a leap year, false otherwise
Example Usage
playground.ts
Notes
- Handles both numbers and numeric strings
- Follows Gregorian calendar rules
- Works with negative years (BC dates)
- Returns
falsefor non-numeric inputs
Type Definition
type Numeric = number | `${number}`;Key Points
- Accurate leap year detection
- Flexible input (numbers or numeric string)
isDateLeapYear
Checks if a given date belongs to a leap year.
Function Signature
function isDateLeapYear(date: Maybe<DateArgs>): boolean;Parameters
date: The date to check. Can bestring,numberorDateobject.
Note
For undefined date argument it uses the current date.
Returns
true if the date belongs to a leap year, false otherwise.
Note
- Internally passes the date's year to
isLeapYearto check if the year is a leap year. - Throws
TypeErrorif the provided date is invalid (not parsable into a valid date byDateConstructor).
Example Usage
playground.ts
Type Definition
type DateArgs = string | number | Date;
type Maybe<T> = T | undefined;Key Points
- Accurate leap year detection
- Flexible input (
numbers,string, orDateobject) - Convenient for date-based checks
Last updated: Sun, Jun 28, 2026 04:11:49AM (UTC)
