The Math of Leap Days 225
The Bad Astronomer writes "We have leap days every four years because the Earth's day and year don't divide evenly. But there's more to it than that... a lot more. A year isn't exactly 365.25 days long, and that leads to needing more complicated math and rules for when we do and don't have a leap year. If you've ever wanted to see that math laid out, now's your chance, and it only comes along every four years. Except every hundred years. Except every four hundred years."
Its not that hard (Score:5, Interesting)
On climagic I laid it out in less than 140 characters. [twitter.com]
Knowing the rules (and not just for leap day) (Score:5, Interesting)
One of my first projects in Computing and Algorithms I in college was to make a calendar that would print out in console with days correctly placed on the day of the week. The instructions specified to take special care for leap day; everyone thought they understood leap day, so no one bothered to check on the rules. The fact that round centuries do not include a leap day except when (year mod 400 = 0) meant that every one of our calendars[1] was wrong for certain years (but right for others, IIRC). And our professor docked us points as such. Back then, the entire class (along with myself) felt that we were misled or cheated, but looking back on it now that was an important lesson on project management, specifically researching requirements and checking with the interested party about how things are.
I reckon this lesson was missed by many, which leads to the various issues we see for software on Leap Day, including Microsoft's Azure as mentioned in a recent /. article.
[1] For the half of the class that completed the project, this 101 class was used to weed out those who couldn't actually program for crap and the EEs just needed a C to meet their requirement.
Re:Complicated? (Score:2, Interesting)
unless it's the turn of the century, cuz those aren't leap years. Unless it's every fourth turn of the century, because those ones are. Hence why 2000 was a leap year, even though according to the century rule it wasn't supposed to be one. 2100 won't be a leap year.
Re:Totally agree. (Score:5, Interesting)
"Deinde, ne in posterum a XII kalendas aprilis aequinoctium recedat, statuimus bissextum quarto quoque anno (uti mos est) continuari debere, praeterquam in centesimis annis; qui, quamvis bissextiles antea semper fuerint, qualem etiam esse volumus annum MDC, post eum tamen qui deinceps consequentur centesimi non omnes bissextiles sint, sed in quadringentis quibusque annis primi quique tres centesimi sine bissexto transigantur, quartus vero quisque centesimus bissextilis sit, ita ut annus MDCC, MDCCC, MDCCCC bissextiles non sint. Anno vero MM, more consueto dies bissextus intercaletur, februario dies XXIX continente, idemque ordo intermittendi intercalandique bissextum diem in quadringentis quibusque annis perpetuo conservetur."
This quote should make the algorithm clear to any competent programmer. Note that it contains the explicit example that in the year 2000, February contains 29 days.
Of course, it can be expressed in many fewer characters in most programming languages. But the pope's astronomer didn't have any programming languages available back in 1582.
It can be fun to point out that the above Latin passage is still the "official" definition of the leap year scheme, since no standards body has tried to revise it. As far as I've been able to determine, that is; let me know if this has ever actually happened. It'd be especially fun if some standards body had tried to rephrase this in a modern language, but got it wrong. If so, they were probably shocked to discover that a 16th-century pope's edict trumped their scientific calcuations.
(The /. software guys might be able to block posting in Russian or Chinese or Arabic, but it's a lot harder to prevent people from using Latin. ;-)
Re:Duh. (Score:4, Interesting)
UTC includes leap seconds. TAI does not.
Re:Our whole calendar is messed up. (Score:4, Interesting)