ArticleslgStudy

computer science

Leap year problem

Leap year problem is a computer science topic covered in the lgStudy science library. This page brings together a partial reference excerpt, illustrations, worked examples, real-world applications and a short study plan, so you can understand Leap year problem rather than just read about it. In short: 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 analog 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…

Key takeaways

  • Leap year problem belongs to computer science; place it in that map before memorising details.
  • Learn the definition first, then one example that makes the definition concrete.
  • Connect Leap year problem to a quantity you can measure, compute or draw — that is where exam questions come from.
  • Reproduce the core statement of Leap year problem from memory before moving on to harder problems.

Reference excerpt

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 analog 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:

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".

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.

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.

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.

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.

The correct leap year algorithm is explained here: Leap year § Gregorian calendar.

Occurrences

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. This bug has been promoted into a requirement in the Ecma Office Open XML (OOXML) specification. In 1996, on December 31, 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 February 29). Repair costs were estimated at more than NZ$1 million. In 2000, on December 31, 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. 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 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 January 1, 2009. Sony's PlayStation 3 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 (see: PlayStation 3 § Leap year bug). In 2012, TomTom satellite navigation devices malfunctioned due to a leap year bug that first emerged on March 31. In 2012, Gmail's chat history showed a date of December 31, 1969, for all chats saved on February 29. In 2012, Microsoft Azure was taken offline by a leap year bug on February 28 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. In 2016, a leap year bug in the luggage conveyor system at Düsseldorf Airport on February 29 caused over 1200 pieces of luggage to miss their flights. In 2024, a leap year bug with the self-payment machines caused pay-at-pump fuelling stations in New Zealand to go offline for more than 10 hours. For more detailed lists of leap year bugs in the years 2016, 2020, and 2024, see the website Code of Matt.

See also Time formatting and storage bugs Year 2100 problem

References

Worked examples

Example 1 — a first encounter with Leap year problem

Start with the simplest possible case. Write down what Leap year problem claims or describes in one sentence, then invent the smallest concrete situation in which that sentence is true. In computer science, the smallest case is usually a single object, a single equation or a single measurement. Check that every symbol or term in your sentence has a meaning in that case.

Example 2 — changing one variable

Take the situation from Example 1 and change exactly one quantity: double it, halve it, or set it to zero. Predict what should happen to Leap year problem before you calculate. Comparing your prediction with the result is the fastest way to find out whether you understand the idea or only the words.

Example 3 — an exam-style question

Typical questions about Leap year problem ask you to (a) state it precisely, (b) apply it to given data, and (c) explain a limitation. Practise writing all three answers in under five minutes; the third part is what separates a full-mark answer from an average one.

Applications of Leap year problem

In research
Leap year problem appears in computer science research whenever the underlying quantities have to be modelled precisely. Papers usually cite it as a starting assumption and then explore where it breaks down.
In technology and industry
Engineering practice reuses Leap year problem in design rules, simulations and safety margins. Knowing the idea lets you read a specification sheet and understand why the numbers look the way they do.
In the classroom
Leap year problem is common in secondary-school and first-year university syllabi. It links to neighbouring topics Calendars, Software bugs, Technology hazards, so understanding it makes those chapters shorter.
In everyday life
Look for Leap year problem outside the textbook — in sport, cooking, traffic, electronics or the sky above you. An example you found yourself is remembered far longer than one you were given.
Ask Teacher Smith questions about this articleOpens your AI tutor with a question about “Leap year problem” →

How to study Leap year problem in 20 minutes

  1. Read the reference excerpt below once, without taking notes.
  2. Close the page and write down what Leap year problem means in your own words.
  3. Compare your version with the excerpt and mark what you missed.
  4. Work through the three examples above with pen and paper.
  5. Explain Leap year problem out loud to somebody else — or to Teacher Smith in the lgStudy chat.

Frequently asked questions

What is Leap year problem in simple terms?

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 analog 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…

Why does Leap year problem matter?

Because it connects several computer science ideas at once: it gives you a definition you can apply, a quantity you can calculate, and a way to check whether a result is plausible.

How should I study Leap year problem?

Read the excerpt, restate it from memory, then work through the examples and applications listed on this page. The five-step study plan above takes about twenty minutes.

What does this page cover?

It gives you a compact reference excerpt plus original lgStudy explanations, examples, applications and study material on Leap year problem.

Tags

  • Calendars
  • Software bugs
  • Technology hazards
  • Time formatting and storage bugs

Keep exploring