Toolbox-XToolbox-X

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

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 false for non-numeric inputs

Type Definition

type Numeric = number | `${number}`;

Use Cases

  • Date validation
  • Calendar applications
  • Age calculations
  • Date arithmetic
  • Financial year calculations

Key Points

  • Accurate leap year detection
  • Flexible input (numbers or numeric string)

Last updated: Fri, May 22, 2026 07:46:19AM (Coordinated Universal Time)

On this page