typodupeerror
×

## The Math of Leap Days225

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."
This discussion has been archived. No new comments can be posted.

## The Math of Leap Days

• #### Duh. (Score:4, Funny)

on Wednesday February 29, 2012 @04:21PM (#39201603)
There are no leap years. It's a conspiracy to cause IT nightmares and bratty kids who claim their age /= 4.
• #### Its not that hard (Score:5, Interesting)

on Wednesday February 29, 2012 @04:29PM (#39201703) Homepage Journal

On climagic I laid it out in less than 140 characters. [twitter.com]

• #### Re: (Score:2, Funny)

by Anonymous Coward

ARRGH, a twitter feed I acutally want to follow.

• #### Length of year, day, etc. (Score:3)

A year is not even exactly 365.2422 days long (if we could actually agree how long a "day" is).
• #### Re: (Score:3)

The 3/1000 difference from .2425 to .2422 results in a Y30K problem. After 30,000 AD, we can relax for a while.
• #### Re: (Score:3)

The 3/1000 difference from .2425 to .2422 results in a Y30K problem. After 30,000 AD, we can relax for a while.
Due to tidal forces slowing the Earth's rotation, in the year 30,000, the day will be about half a second longer resulting in the year being only 365.2401 days long, so we will need to adjust our algorithms a lot sooner than that
• #### Re: (Score:3)

If the days would become shorter, that means we'd be able to drop the %400 rule somewhere between now and Y30K, but since a day is actually slightly longer than what our current algorithm accounts for, the two might just cancel eachother out to let the algorithm last well beyond 30K. I'm too lazy to try and do the math to verify.

• #### Re: (Score:3)

Not that much of a Nightmare, at least with modern Data classes. You take the month and year you are looking at. date(Year, Month+1, Day = 1) - 1 day. Then you get the last day of every month. Leap Year isn't the nightmare, The nightmare is the normal Month system with different days each month.
• #### Re:Duh. (Score:5, Informative)

on Wednesday February 29, 2012 @05:50PM (#39202649) Homepage

No, the REAL nightmare for programmers is daylight savings time. Especially in the spring, when local times jump back and repeat. Ugh.

• #### Re:Duh. (Score:5, Insightful)

<[moc.liamg] [ta] [ammage]> on Wednesday February 29, 2012 @05:57PM (#39202717)

No, the REAL nightmare for programmers is daylight savings time. Especially in the spring, when local times jump back and repeat. Ugh.

That's why you should save the time in UTC format, and then let the OS help you translate that into a display time.

• #### Re: (Score:2)

It is still a nightmare though. Just for a different programmer and not you. You have to approach the problem by reading the time first, then deciding on how to store it. That means you need to rely on that system, and some may be better than others. I would think most systems are relying on Linux and the zoneinfo files to get the time correctly.

So some programmer still needs to deal with the fallout from the fucktarded Congress Critters that decided to tank millions of devices worldwide that depended o

• #### Re: (Score:2)

Time should be like internationalization. Everything internally is UTC or at last based on something other than local time; and strings are all multibyte. Everything is passed around this way untouched, uninterpreted. The only time you deal with locale settings is just before outputting the values and just after inputting them.

And yet people keep getting this wrong... You end up with a customer whose facilities straddle a time zone boundary, or the server and client are in different time zones, and then

• #### Re: (Score:2)

Twice a year I get marketing people coming to me and asking what happens to the product that doesn't have a certain bug fix. And twice a year they write it down, and promise to get some QA to test it to be really sure.

Everything should be in UTC. Except that we have to integrate with products that insist on local time. Or bizarre time formats.

• #### Re:Duh. (Score:5, Informative)

on Wednesday February 29, 2012 @10:22PM (#39204685)

Here is one the UTC/DST problems in a nutshell, and why it's not as simple as you think:
Assumptions:
-Me and my user are in UTC +10
-DST puts us into UTC +11
-DST runs from 1 October until 1 April

I am writing a "family reminders" application for mobile phones. A user enters two reminders. BOTH reminders are activated for the user and his wife, reminding them to take some medication. One is for 10 March 2010 at 1130AM and the other is for 10 April 2010 at 1130AM.

How do I store these date? I am a SMART programmer, and I store them as 2012-03-10_0030 and 2012-04-10_0130.
I was clever. I looked at the user's timezone setting, projected into the dates they were setting to appropriately modify the UTC time depending on DST or not.

Two things happen:
1. The user's wife flies to the west coast on 9 march, 3 hours earlier. On 10 march, do we alarm her at 8:30, per UTC? Or do we look at her new current time zone vs when it really was set and alarm her at 11:30 local time?

2. The "making summer longer" act is passed, extending DST to 15 April. Do we alarm them at 11:30am, or at 12:30pm? Why?

The solution to both of these is to give the users a bunch of checkboxes they don't quite understand, or to make assumptions that might wind up incorrect. Either way there's no "win win".

• #### For years (Score:5, Funny)

on Wednesday February 29, 2012 @04:22PM (#39201619) Journal

and it only comes along every for years.

Wow! That really IS rare!

• #### Re: (Score:3)

The slashdot editors were probably just reading an alien cookbook and got confused.
• #### Re: (Score:2)

for(int years = 0; years LENTH_OF_UNIVERSE; i++) { /* article */ }

• #### Re: (Score:2, Funny)

by Anonymous Coward

That must be the American spelling: there's no "u".

• #### Re: (Score:2)

The person who wrote the summary was a math wiz, not an english major.
• #### Re: (Score:3)

Nope. Probably not a math wiz, either.

• #### Re: (Score:2)

It's just long enough that the original devs probably thought "I don't want to deal with this just yet" and put in a broken time system. Then 3 years later those devs are long gone when the bug reports start flooding in.

• #### Complicated? (Score:5, Insightful)

by Anonymous Coward on Wednesday February 29, 2012 @04:22PM (#39201621)

I think we have different definitions of complicated.

• #### Re:Complicated? (Score:5, Funny)

on Wednesday February 29, 2012 @04:33PM (#39201769)

I think we have different definitions of complicated.

Evidently spelling and grammar top the list for the /. editors.

• #### Re: (Score:2)

Well, even when it was just a leap year every 4 years, folks managed to get it wrong, and only in 4AD someone pointed out the error in how the recommendations of mathematicians/astronomers employed by Julius Caesar had been interpreted. Between the reform (45BC) and 4AD leap years happened once per 3 years.

• #### Now's your chance? (Score:2)

I'm pretty sure the math doesn't go anywhere. It's not Brigadoon.

In fact I'm going to take the URL and put it in my calendar for next June.

Will report back ....

• #### Lets use the Myan Calendar (Score:2)

Oh wait, it ends in 2012!
• #### Re:Lets use the Myan Calendar (Score:5, Funny)

on Wednesday February 29, 2012 @04:38PM (#39201829) Journal
did your "Myans" invent the number "for"?
• #### Re: (Score:2)

I give up. What did they invent numbers for?

Nice sig, btw.
• #### Re: (Score:2)

Or So says the Evangelical Christians. However I am not sure why they are basing their information on a Pagan Calendar.
• #### Re: (Score:2)

Why not? They dont know when jesus was born so they took the winter soltise and said this is when we celebrate.

• #### Re: (Score:3)

Oh wait, it ends in 2012!

No, it doesn't... just most of the digits turn to "0"... in fact, the remaining radial digit of the number representing the year will not be a "1" either, as in when we moved from 99 A.D. to 100 A.D. No, in fact, they were already on the 12th cycle, so the calendar already could express more years than just 2012 A.D. and we never had to add anything to their calendar system to do so...

• #### Knowing the rules (and not just for leap day) (Score:5, Interesting)

<tukaro AT gmail DOT com> on Wednesday February 29, 2012 @04:32PM (#39201757) Homepage Journal

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.

• #### Wait, what? (Score:5, Funny)

on Wednesday February 29, 2012 @04:32PM (#39201759)
How is this news? It's been in Wikipedia for years [wikipedia.org]!
• #### Re: (Score:3)

Today is Feb 29, a leap day, that's why it's relevant. Tomorrow, it will be far less so.

• #### A video with visualisations (Score:3, Informative)

on Wednesday February 29, 2012 @04:34PM (#39201785)
• #### Four days too late! (Score:5, Informative)

on Wednesday February 29, 2012 @04:38PM (#39201831)

The extra, or "bissextile" day is actually inserted immediately after February 23.

The Romans picked up the Egyptians' idea of treating a common year as 360+5 days, since 360 is a highly composite number and all (the Mayans ended up doing the same). But instead of treating the extra 5 days as "epagomenal" (outside any month), they were treated as the last five days before the first month of spring, i. e. the last five days of February.

Treating the five-day block of Feb 24 through Feb 28 as inviolate meant inserting the extra day (previously an extra month) before it.

This is why the Christian feast of Saint Matthias has historically been observed on February 24 in common years and February 25 in leap years; it's always the fifth ("sixth," if you lack an understanding of zero) day before the calends of March.

• #### Re: (Score:2)

Er, five days too late.

Fuck my non-life.

• #### leap days make ood codeing bugs show up some times (Score:3)

on Wednesday February 29, 2012 @04:43PM (#39201897)
• #### Misidentifying the source of the problem (Score:2)

leap days make ood codeing bugs show up some times

When code does not correctly model the problem domain, the error isn't with the domain.

• #### Who are we kidding? The real reason for leap days: (Score:2)

To give first-time programming students a fun and interesting homework assignment.

• #### WTH? (Score:2)

Whats with all the leap stuff?
Yes, I know it's a leap year, but the only other time I remember seeing so much stuff about it being circulated was in 2000.
Still, why are adults explaining it to other adults? Is this one different? Is the world getting so mellow that a leap year is no an excuse for a lengthy discussion on a reletivly trivial event? Trivial in that the rules are pretty simple. Not trivial as in little impact.

• #### Re: (Score:2)

We all just need to add to our post count.
• #### A modest proposal (Score:2)

There's a very, very simple solution to this, and that is: At some value UTC, we all light model rocket engines with the exhaust facing east, and slow down the day such that its length goes evenly into a year. Any over/undershoot in the quantity or duration of burns can be adjusted on a much smaller scale. After that we just perform regular burns in the opposite direction to maintain angular momentum. Voila!

• #### drop astronomy for Planck units (Score:2)

Chose an aribitrary starting time, say the origin of this universe about 8 x 10^60 Plank units ago.

#### Related LinksTop of the: day, week, month.

To do two things at once is to do neither. -- Publilius Syrus

Working...