A leap year bug is a code defect that creates a problematic, unintended outcome when executed within the context of a leap year, typically within the proleptic Gregorian calendar system.
The last leap year was 2016. The next leap years are 2020 and 2024.
There are two attributes that are unique to leap years:
- Leap years have a February 29th, while common years do not.
- Leap years have 366 days in total, while common years have only 365.
This post is intended to help others understand the nature of leap year bugs, what they look like in various languages, and how to correct them.
Leap year bugs typically fall into two impact categories:
- Category 1: Those that lead to error conditions, such as exceptions, error return codes, uninitialized variables, or endless loops
- Category 2: Those that lead to incorrect data, such as off-by-one problems in range queries or aggregation
With each answer, please indicate the programming language and/or platform, as well as the impact category as defined above. (Follow the template used by existing answers please.)
Please create one separate answer per language and type of defect, and vote for your favorite, especially those you have personally encountered (leaving comments with anecdotes where possible).
I will seed a few answers to get started, and update with additional examples over time.