Leap Year

General

// Definition

A year with 366 days that adds 29 February to keep the calendar aligned with Earth's orbit. The rule: a year is a leap year if divisible by 4, except years divisible by 100 are not leap years — unless also divisible by 400 (2000 was a leap year; 1900 was not). This three-part rule is a frequent source of off-by-one bugs: developers who only check divisibility by 4 will incorrectly treat 1900, 2100, and 2200 as leap years. In QA, 29 February is a canonical boundary-value test case for any date field: it should be rejected in non-leap years and accepted in leap years. Systems that compute ages or date differences must also handle the February 29 to March 1 transition in non-leap years correctly. The unambiguous formula is: (year % 4 === 0) && (year % 100 !== 0 || year % 400 === 0).

// Related terms