Leap year bug
   HOME

TheInfoList



OR:

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 year A leap year (also known as an intercalary year or bissextile year) is a calendar year that contains an additional day (or, in the case of a lunisolar calendar, a month) added to keep the calendar year synchronized with the astronomical year or ...
s, 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: # 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". from datetime import date today = date.today() later = today.replace(year = today.year + 1)


Windows C++

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. SYSTEMTIME st; FILETIME ft; GetSystemTime(&st); st.wYear++; SystemTimeToFileTime(&st, &ft);


Microsoft C#

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. DateTime dt = DateTime.Now; DateTime result = new DateTime(dt.Year + 1, dt.Month, dt.Day);


JavaScript

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. var dt = new Date(); dt.setFullYear(dt.getFullYear() + 1);


Bad leap year algorithm (many languages)

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. bool isLeapYear = year % 4

0;
The correct leap year algorithm is explained at Leap Year Algorithm.


Occurrences

There have been many occurrences of leap year bugs: *
Microsoft Excel Microsoft Excel is a spreadsheet developed by Microsoft for Microsoft Windows, Windows, macOS, Android (operating system), Android and iOS. It features calculation or computation capabilities, graphing tools, pivot tables, and a macro (comp ...
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 Lotus 1-2-3 is a discontinued spreadsheet program from Lotus Software (later part of IBM). It was the first killer application of the IBM PC, was hugely popular in the 1980s, and significantly contributed to the success of IBM PC-compatibles i ...
, and was purposely implemented in Excel for the purpose of
backward compatibility Backward compatibility (sometimes known as backwards compatibility) is a property of an operating system, product, or technology that allows for interoperability with an older legacy system, or with input designed for such a system, especiall ...
. Microsoft has written an article about this bug, explaining the reasons for treating 1900 as a leap year.Excel incorrectly assumes that the year 1900 is a leap year
Retrieved 2019-05-01.
This bug has been promoted into a requirement in the Ecma Office Open XML (OOXML) specification.
Retrieved 2016-09-10.

Retrieved 2016-09-10.
* In 1996, two aluminum smelting plants at
Tiwai Point Tiwai Point lies at the entrance to Bluff Harbour on the southern coast of the South Island of New Zealand. A spit which extends from the western end of the Awarua Plain, it lies between Awarua Bay to the north and Foveaux Strait to the sout ...
, New Zealand, and Bell Bay, Tasmania, Australia, experienced a leap year bug on December 31, when each of the 660 computers controlling the smelting potlines shut down at the stroke of midnight simultaneously and without warning. The computers were not programmed to handle the 366th day of the year. Repair costs were estimated at more than . * At midnight on December 31, 2008, many first generation Zune 30 models froze. Microsoft stated that the problem was caused by the internal clock driver written by
Freescale Freescale Semiconductor, Inc. was an American semiconductor manufacturer. It was created by the divestiture of the Semiconductor Products Sector of Motorola in 2004. Freescale focused their integrated circuit products on the automotive, embedd ...
and the way the device handles a
leap year A leap year (also known as an intercalary year or bissextile year) is a calendar year that contains an additional day (or, in the case of a lunisolar calendar, a month) added to keep the calendar year synchronized with the astronomical year or ...
. 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 January 1, 2009. * Sony's
PlayStation 3 The PlayStation 3 (PS3) is a home video game console developed by Sony Interactive Entertainment, Sony Computer Entertainment. The successor to the PlayStation 2, it is part of the PlayStation brand of consoles. It was first released on Novemb ...
incorrectly treated 2010 as a leap year, so the non-existent February 29, 2010, was shown on March 1, 2010, and caused a program error. * In 2012,
TomTom TomTom N.V. is a Dutch multinational developer and creator of location technology and consumer electronics. Founded in 1991 and headquartered in Amsterdam, TomTom released its first generation of satellite navigation devices to market in 2004 ...
satellite navigation devices malfunctioned due to a leap year bug that first emerged on March 31. * In 2012,
Gmail Gmail is a free email service provided by Google. As of 2019, it had 1.5 billion active users worldwide. A user typically accesses Gmail in a web browser or the official mobile app. Google also supports the use of email clients via the POP and ...
's chat history showed a date of December 31, 1969, for all chats saved on February 29. * In 2012,
Microsoft Azure Microsoft Azure, often referred to as Azure ( , ), is a cloud computing platform operated by Microsoft for application management via around the world-distributed data centers. Microsoft Azure has multiple capabilities such as software as a ...
was taken offline by the leap year bug on February 28. At 5:45 PM PST the Windows Azure team became aware of an issue, apparently due to a time calculation that was incorrect for the leap year. * In 2016, a large number of leap year bugs were cataloged i
List of 2016 Leap Day Bugs
at the website ''Code of Matt''. * In 2016, a leap year bug in the luggage conveyor system at
Düsseldorf Airport Düsseldorf Airport (german: link=no, Flughafen Düsseldorf, ; until March 2013 ''Düsseldorf International Airport''; ) is the international airport of Düsseldorf, the capital of the German state of North Rhine-Westphalia. It is about north ...
on February 29 caused over 1,200 pieces of luggage to miss their flights. * In 2020 a large number of leap year bugs were cataloged i
List of 2020 Leap Day Bugs
at the website ''Code of Matt''.


See also

*
Time formatting and storage bugs In computer science, time formatting and storage bugs are a class of software bugs that may cause time and date calculation or display to be improperly handled. These are most commonly manifestations of arithmetic overflow, but can also be the re ...
* Year 2100 problem


References

{{DEFAULTSORT:Leap Year Bug Time formatting and storage bugs Calendars Software bugs Technology hazards