Leap year bugs typically fall into two categories, based on the amount of impact they may have in real-world usage:1
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
The correct leap year algorithm is explained here: Leap year § Gregorian calendar.
See also: Year 2000 problem § On 29 February and 1 March 2000
Johnson-Pint, Matt. "What are some examples of leap year bugs?". Stack Overflow. Retrieved 5 February 2020. https://stackoverflow.com/questions/57530882/what-are-some-examples-of-leap-year-bugs ↩
Johnson-Pint, Matt. "Python - Replacing the year". Stack Overflow. Retrieved 29 February 2020. https://stackoverflow.com/a/60468711/634824 ↩
Johnson-Pint, Matt. "Win32 / C++ SYSTEMTIME struct manipulation". Stack Overflow. Retrieved 5 February 2020. https://stackoverflow.com/a/57530901/634824 ↩
Johnson-Pint, Matt. ".NET / C# - Construction from date parts". Stack Overflow. Retrieved 5 February 2020. https://stackoverflow.com/a/57530883/634824 ↩
Johnson-Pint, Matt. "JavaScript - Adding Year(s)". Stack Overflow. Retrieved 5 February 2020. https://stackoverflow.com/a/59865749/634824 ↩
Johnson-Pint, Matt. "Determining if a Year is a Leap Year". Stack Overflow. Retrieved 5 February 2020. https://stackoverflow.com/a/59865989/634824 ↩
Excel incorrectly assumes that the year 1900 is a leap year. Retrieved 2019-05-01. https://docs.microsoft.com/office/troubleshoot/excel/wrongly-assumes-1900-is-leap-year ↩
Standard ECMA-376 / Open Office XML File Formats. Retrieved 2016-09-10. http://www.ecma-international.org/publications/standards/Ecma-376.htm ↩
ISO/IEC 29500 / Open Office XML File Formats. Retrieved 2016-09-10. http://standards.iso.org/ittf/PubliclyAvailableStandards/index.html ↩
Towler, Jim (7 January 1997). "Leap-Year software bug gives "Million-dollar glitch"". The RISKS Digest. 18 (74). ACM Committee on Computers and Public Policy. Retrieved 5 February 2020. https://catless.ncl.ac.uk/Risks/18.74.html#subj5 ↩
"The last bite of the bug". BBC News. 5 January 2001. http://news.bbc.co.uk/1/hi/sci/tech/1101917.stm ↩
"7-Eleven Systems Hit by Y2k-like Glitch". Retrieved 10 March 2023. https://www.computerworld.com/article/2590234/7-eleven-systems-hit-by-y2k-like-glitch.amp.html ↩
"Y2K Bug Hits Norway's Railroad At End Of Year". 1 January 2001. Retrieved 10 March 2023. https://greensboro.com/y2k-bug-hits-norways-railroad-at-end-of-year/article_82a866cf-3046-51ce-9aae-efd2bf3abc58.html ↩
"Home - Microsoft Answers". Forums.zune.net. Archived from the original on August 30, 2009. Retrieved 2011-07-27. https://web.archive.org/web/20090830061109/http://forums.zune.net/412486/ShowPost.aspx ↩
John Herrman (2008-12-31). "30GB Zunes Failing Everywhere, All At Once". Gizmodo.com. Archived from the original on 2011-08-12. Retrieved 2011-07-27. https://web.archive.org/web/20110812004148/http://gizmodo.com/5121311/30gb-zunes-failing-everywhere-all-at-once ↩
Geere, Duncan (31 December 2008). "BREAKING: Zunes worldwide hit by mystery crash : Tech Digest". Techdigest.tv. Retrieved 2011-07-27. http://www.techdigest.tv/2008/12/breaking_zunes.html ↩
"Zune 30 FAQ". Microsoft. December 31, 2008. Archived from the original on January 2, 2009. Retrieved January 1, 2009. https://web.archive.org/web/20090102065939/http://www.zune.net/en-us/support/zune30.htm ↩
Zadegan, Bryant (January 3, 2009). "A lesson on infinite loops". AeroXperience. Retrieved January 5, 2009. http://winjade.net/2009/01/lesson-on-infinite-loops/ ↩
"Sony fixes PS3 leap year bug". Metro. 2 March 2010. Retrieved 10 October 2019. https://metro.co.uk/2010/03/02/sony-fixes-ps3-leap-year-bug-138471/ ↩
"TomTom sat-nav devices hit by GPS 'leap year bug'". BBC News. 3 April 2012. Retrieved 5 February 2020. https://www.bbc.com/news/technology-17599701 ↩
"Summary of Windows Azure Service Disruption on Feb 29th, 2012". azure.microsoft.com. 9 March 2012. Retrieved 23 January 2025. http://azure.microsoft.com/en-us/blog/summary-of-windows-azure-service-disruption-on-feb-29th-2012/ ↩
Johnson-Pint, Matt (29 February 2016). "List of 2016 Leap Day Bugs". Code of Matt. Retrieved 5 February 2020. https://codeofmatt.com/list-of-2016-leap-day-bugs ↩
"Airport hiccup leaves 100s of passengers pantless". The Local (de). March 2016. Retrieved 5 February 2020. https://www.thelocal.de/20160301/dsseldorf-airport-hick-ups-leave-hundreds-of-customers-without-underwear ↩
Johnson-Pint, Matt (29 February 2020). "List of 2020 Leap Day Bugs". Code of Matt. Retrieved 9 March 2020. https://codeofmatt.com/list-of-2020-leap-day-bugs ↩
"List of 2024 Leap Day Bugs". Code of Matt. 2024-02-29. Retrieved 2024-02-29. https://codeofmatt.com/list-of-2024-leap-day-bugs/ ↩
"Petrol pumps back online after day-long outage blamed on leap year glitch". The New Zealand Herald. 2024-03-01. Retrieved 2024-02-29. https://www.nzherald.co.nz/hawkes-bay-today/news/february-29-allied-fuel-pumps-around-nz-ground-to-a-halt-as-systems-forget-leap-year/XEQBK5JLBZG6LO3VGUQ6Q2WGC4/ ↩