The leap year problem (also known as the leap year bug or the leap day bug) is a problem for both digital (computer-related) and non-digital documentation and data storage situations which results from errors in the calculation of which years are leap years, or from manipulating dates without regard to the difference between leap years and common years.
Categories
Leap year bugs typically fall into two categories, based on the amount of impact they may have in real-world usage:[1]
Those that lead to error conditions, such as exceptions, error return codes, uninitialized variables, or endless loops
Those that lead to incorrect data, such as off-by-one problems in range queries or aggregation
Examples
Python
The following Python code is an example of a Category 1 leap year bug. It will work properly until today becomes February 29. Then, it will attempt to create a February 29 of a common year, which does not exist. The date constructor will raise a ValueError with the message "day is out of range for month".[2]
The following Windows C++ code is an example of a Category 1 leap year bug. It will work properly until the current date becomes February 29 of a leap year. Then, it will modify st to represent February 29 of a common year, a date which does not actually exist. Passing st to any function that accepts a SYSTEMTIME struct as a parameter will likely fail.
For example, the SystemTimeToFileTime call shown here will return an error code. Since that return value is unchecked (which is extremely common), this will result in ft being left uninitialized.[3]
The following .NET C# code is an example of a Category 1 leap year bug. It will work properly until dt becomes February 29. Then, it will attempt to create a February 29 of a common year, which does not exist. The DateTime constructor will throw an ArgumentOutOfRangeException.[4]
The following JavaScript code is an example of a Category 2 leap year bug. It will work properly until dt becomes February 29, such as on 2020-02-29. Then it will attempt to set the year to 2021. Since 2021-02-29 doesn't exist, the Date object will roll forward to the next valid date, which is 2021-03-01.[5]
The following code is an example of a leap year bug that is seen in many languages. It may cause either a Category 1 or Category 2 impact, depending on what the result is used for. It incorrectly assumes that a leap year occurs exactly every four years.[6]
Microsoft Excel has, since its earliest versions, incorrectly considered 1900 to be a leap year, and therefore that February 29 comes between February 28 and March 1 of that year. The bug originated from Lotus 1-2-3, and was purposely implemented in Excel for the purpose of backward compatibility. Microsoft has written an article about this bug, explaining the reasons for treating 1900 as a leap year.[7] This bug has been promoted into a requirement in the Ecma Office Open XML (OOXML) specification.[8][9]
In 1996, on December31, at two aluminum smelting plants at Tiwai Point, New Zealand and Bell Bay, Tasmania, Australia, each of the 660 computers controlling the smelting potlines shut down at midnight since the computers were not programmed to handle the 366th day of the year (1996 being a leap year and having contained a February29). Repair costs were estimated at more than NZ$1 million.[10]
In 2000, on December31, in Norway the national railroad company Vy discovered all 29 of its new Signatur trains failed to run because their onboard computers did not recognize the date as the 366th day of the year. As an interim measure, engineers restarted the trains by resetting their clocks back by a month.[11][12][13]
At midnight on December31, 2008, many[14] first generation Zune 30 models froze.[15][16] Microsoft stated that the problem was caused by the internal clock driver written by Freescale and the way the device handles a leap year. It automatically fixed itself 24 hours later, but an intermediate "fix" for those who did not wish to wait was to drain the device's battery and then recharge after noon UTC on January1, 2009.[17][18]
Sony's PlayStation 3 incorrectly treated 2010 as a leap year, so the non-existent February29, 2010, was shown on March1, 2010, and caused a program error (see: PlayStation 3 § Leap year bug).[19]
In 2012, TomTom satellite navigation devices malfunctioned due to a leap year bug that first emerged on March31.[20]
In 2012, Microsoft Azure was taken offline by a leap year bug on February28 that caused virtual machines to crash upon startup. At 5:45 p.m. PST the Windows Azure team became aware of an issue, which was eventually discovered to be caused by a "one year from now" operation that involved changing the year without changing the day.[21]
In 2016, a leap year bug in the luggage conveyor system at Düsseldorf Airport on February29 caused over 1,200 pieces of luggage to miss their flights.[23]