Think about Loose Coupling PerlMonks

### Answer: Leap Year

 on Sep 15, 2000 at 02:52 UTC Need Help??

Q&A > dates and times > How do I determine if a given year is a leap year? - Answer contributed by Adam

The leap year formula is:

A leap year is divisable by 4, but not by 100 (except if divisable by 400.)

```if( 0 == \$year % 4 and 0 != \$year % 100 or 0 == \$year % 400 )
{
# Then \$year is a leap year.
}

Replies are listed 'Best First'.
RE (tilly) 1: Answer: Leap Year
by tilly (Archbishop) on Sep 15, 2000 at 13:24 UTC
Note that the answer to this question depends on your calendar. The standard Unix cal program assumes that the calendar switched from the Julian to the Gregorian in 1752. (Hence leading to an odd-looking September. BTW the man page I have does not mention the fact that the date chosen is English-centric. The bored and curious may want to see the actual statute or general background on the change.) Prior to that the century and four century correction terms did not apply.

Incidentally the solar year is currently 365d 5h 48m 46.069s which is not fully accounted for by the Gregorian Calendar so there is talk of some day adding another correction term. This is unlikely to be an issue in the lifetimes of anyone reading this though. :-)

Yes. I assumed that you were using the Gregorian calander.
(regardless of what year your country switched to it.)

Protestant England switched to the Gregorian in 1752, but the Catholic nations switched in 1582. Other groups did not switch until as late as the 20th century. Calanders are funny things in that they represent a societal contract to delude ourselves as a group that we know what time it is.

Reality check: We do not know what time it is because time is relative. There are two important facts:

1. Time moves forward only. When did time begin? We don't know, so we make up a start point. (This is, admitadly, a secular argument*, but as my second point reveals, even the non-secular "dawn of time" does not work either.)
2. How do you measure time? The US Navy does it with 54 atomic clocks in dispersed vaults, including 10 hydrogen masers and 44 cesium beam devices. In other words, they picked something that does something at a reasonably steady rate, and the measured it. But even that is not trully precise. As Einstein proved, time progresses at different rates dependant on the velocity of the observer. Add that into gravitational forces altering our orbit around the sun, and suddenly every year is a different length.
Time is the great cosmic joke. It is much easier to buy into the group delusion that we know what time it is. It makes it possible to schedule things like trains, tele-conferences, lunch. What I'm saying, Tilly, is that calculating anything having to do with time requires some basic assumptions from the parties involved. The most prevelant calander on the planet is the Gregorian, so we use Gregory's rule and if enough different governing bodies ever agree to muck with that and 'fix' the inherint errors, then this will change.

But what really needs fixing? Does it matter (really) if the month of December happens to fall in the summer in the year 5300 something??** People have been tinkering with calanders since we first started making them. (Julieus Ceaser had July, the month with the most daylight, named after him. Augustus Ceaser followed him both as Emporer and Month maker and took the month with next greatest amount of sun light... he even took a day from February to bring August up to 31, matching July. )

But I digress, we are here to talk Perl, not to waste time talking about time. You included some good links, I suggest that people interested in this stuff read them. Another good one is the Claus Tondering Calander FAQ.

*An interesting point that I read somewhere was that the Muslim calander actually shifts the months around through the year, so that Ramadan will occur during all the seasons in a person life.

**As chromatic mentioned to me in a chatterbox msg, December fell in the summer this year too... south of the Equator. More evidence that calanders are contrived.

Create A New User
Chatterbox?
and the daffodils sway...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (4)
As of 2018-06-19 22:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should cpanminus be part of the standard Perl release?

Results (115 votes). Check out past polls.

Notices?