Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

1 stupid question about Leap Year

17 views
Skip to first unread message

rb

unread,
Jun 27, 1999, 3:00:00 AM6/27/99
to

I'm sort of unclear how to calculate which year is a leap year. This is a
function from calendar.pas (samples).

function TCalendar.IsLeapYear(AYear: Integer): Boolean;
begin
Result := (AYear mod 4 = 0) and ((AYear mod 100 <> 0) or (AYear mod 400 =
0));
end;

It implies (if I understand this properly) that in order to tell that a year
is a leap year, the number has to be divisible by 4 and has to be either NOT
divisible by 100 but divisible by 400.

We all know that the year 2000 is a leap year, right? Write down all leap
years through year 2100. Is 2100 not a leap year too? Don't think it meets
function's criteria. As a matter of fact, try to set Feb/2100 in
calendar.pas and see what happens. Same problem with every other date
component I've seen.

Am I missing something here? Is 25 x 4 not 100 any more?

Thanks.

Finn Tolderlund

unread,
Jun 27, 1999, 3:00:00 AM6/27/99
to
The rule is:
A year which is dividable by 100 is not a leap year, except if it is also
dividable by 400.
So 2000 is a leap year, 1900 and 2100 are not leap years.

rb <r...@quantum.ca> skrev i en
nyhedsmeddelelse:7l5lqa$kg...@forums.borland.com...


>
> I'm sort of unclear how to calculate which year is a leap year. This is a
> function from calendar.pas (samples).

Ray Lischner

unread,
Jun 27, 1999, 3:00:00 AM6/27/99
to
On Sun, 27 Jun 1999 13:12:49 -0400, "rb" <r...@quantum.ca> wrote:

>Is 2100 not a leap year too?

2100 is not a leap year.

--
Ray Lischner (http://www.tempest-sw.com/)
Author of "Hidden Paths of Delphi 3: Experts, Wizards, and the Open Tools API"

Pete Cervasio

unread,
Jun 27, 1999, 3:00:00 AM6/27/99
to
On Sun, 27 Jun 1999 13:12:49 -0400, "rb" <r...@quantum.ca> wrote:

>It implies (if I understand this properly) that in order to tell that a year
>is a leap year, the number has to be divisible by 4 and has to be either NOT
>divisible by 100 but divisible by 400.

Yes, a leap year is a year that is an even multiple of 4, unless it's
an even multiple of 100. In that case, it has to be an even multiple
of 400 to be considered a leap year.

For example:

1800: No
1900: No
2000: Yes
2100: No
2200: No
2300: No
2400: Yes

[more snip]


>function's criteria. As a matter of fact, try to set Feb/2100 in
>calendar.pas and see what happens. Same problem with every other date
>component I've seen.

Those data components are acting correctly. 29 Feb 2100 does not
exist, so it is not really a "problem". It's the same as asking for
December 45th in any year. :)

Best regards,
Pete C.

=================================================================
I'm really cervasio at airmail dot net, if you want to email me.
Fight spam...Join CAUCE! Learn more at http://www.cauce.org
All UCE goes to my ISP's abuse dept. They get people terminated!
=================================================================

rb

unread,
Jun 27, 1999, 3:00:00 AM6/27/99
to
Guys,

Thanks for your responses, though I'd use some brute force to verify this
calculation:

2000, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72,
76, 80, 84, 88, 92, 2096 AND 2100.

How do you explain this?

Wayne Niddery (TeamB)

unread,
Jun 27, 1999, 3:00:00 AM6/27/99
to
rb wrote in message <7l62d0$l1...@forums.borland.com>...

Explain what? 2100 is divisible by 4 and by 100, but NOT divisible by 400,
so it's NOT a leap year. That's the rule. The calculation you saw is
correct. To break it into discrete parts it could be this:

if year mod 400 = 0 then leap := True
else if year mod 100 = 0 then leap := False
else if year mod 4 = 0 then leap := True
else leap := False;

But the code you posted is MUCH more efficient. BTW the code you posted is
identical to that in Delphi's IsLeapYear function found in SysUtils.

--
Wayne Niddery - WinWright Consulting
RADBooks - http://home.ican.net/~wniddery/RADBooks.html
Bill of NO Rights; ARTICLE II: You do NOT have the right to never be
offended. This country is based on freedom, and that means freedom for
everyone not just you! You may leave the room, change the TV channel,
express a different opinion, etc., but you may still be offended. That's
YOUR problem.

rb

unread,
Jun 27, 1999, 3:00:00 AM6/27/99
to
You're right, IsLeapYear was taken from control.pas as I said in my first
message.

> >
> >2000, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68,
72,
> >76, 80, 84, 88, 92, 2096 AND 2100.
> >
> >How do you explain this?
>
> Explain what? 2100 is divisible by 4 and by 100, but NOT divisible by 400,
> so it's NOT a leap year. That's the rule. The calculation you saw is

Here you go again. You're taking their function for granted. All I'm asking
you to do is to think about the array I wrote previously. Or better yet,
tell me if the year 2096 is a leap year. If it is, how can it be that 4
years later, the year 2100 doesn't get to be a leap one. That would also
mean that the year 2004 IS a leap year. That makes 8 years leap. I'm very
sorry but I'm having a hard time understanding this.

rb

rb

unread,
Jun 27, 1999, 3:00:00 AM6/27/99
to

Ray Lischner <delphi.at.te...@nospam.com> wrote in message
news:3777ba32...@forums.inprise.com...

> On Sun, 27 Jun 1999 16:47:39 -0400, "rb" <r...@quantum.ca> wrote:
>
> >Thanks for your responses, though I'd use some brute force to verify this
> >calculation:
> >
> >2000, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68,
72,
> >76, 80, 84, 88, 92, 2096 AND 2100.
> >
> >How do you explain this?
>
> You can write down any numbers you want, but that doesn't change the
> fact that 2100 is not a leap year. If you don't believe us, try the
> National Institute for Standards and Technology:
> http://www.bldrdoc.gov/timefreq/faq/faq.htm#18
>
That's great. I've replied to the other guy with the same theory:

Jeff Overcash (TeamB)

unread,
Jun 27, 1999, 3:00:00 AM6/27/99
to
2096 is a leap year. 2100 will not be a leap year. 2104 will be a leap year.
The problem is that the Solar year for the earth is a little more than 365
days. It is closer to 365.25 days. Every four years we have a leap year to
eliminate the excess .25's over the previous 4 years. The problem with this is
that is is not exactly .25 either it is .242. So to correct the remaining error
every 100 years we do not have a leap year except on the 400th year.

You are making a mountain out of a mole hill here. This is the scientifically
accepted way of figuring out leap years. All a leap year is is an error
correction to keep the same day of the year to represent the same relative
position in space to the Sun.

What part of "Leap years are necessary because the actual length of a year is
365.242 days, not 365 days, as commonly stated. Therefore, on years that are
evenly divisible by 4 (like 1992, for example) an extra day is added to the
calendar on February 29th. However, since the year is slightly less than 365.25
days long, adding an extra day every 4 years results in about 3 extra days being
added over a period of 400 years. For this reason, only 1 out of every 4 century
years is considered as a leap year." didn't you understand? This is all based
on science. If you don't want to trust the science behind this then I think
there is a meeting of the Flat Earth Society starting in a few hours <vbg>.

rb wrote:
>
> You're taking their function for granted. All I'm asking you to do is to
> think about the array I wrote previously. Or better yet, tell me if the year
> 2096 is a leap year. If it is, how can it be that 4 years later, the year
> 2100 doesn't get to be a leap one. That would also mean that the year 2004
> IS a leap year. That makes 8 years leap. I'm very sorry but I'm having a
> hard time understanding this.
>
> rb

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Maybe it was infatuation or the thrill of the chase.
Maybe you were always beyond my reach and my heart was playing safe.
But was that love in your eye I saw or the reflection of mine?
Give me time, won't you give me that time!
Welcome back to the circus. (Fish)
--

Rob Kennedy

unread,
Jun 27, 1999, 3:00:00 AM6/27/99
to
The reason is because Earth does not revolve around the sun in exactly 365
days. Most people round to 365.25 days. So every four years, we add on
another day to catch up our clocks with the planet. The number is closer to
365.24, which means that every 100 years, we don't need to add a day because
we've been adding a little over a day every four years. However, even that
compensation doesn't get it right, so every 400 years we have to add a day
back on. This system works right now, but don't try to predict too far into
the future, since there are probably more leap days that need to be adjusted
beyod the 400-year mark.

--Rob

rb <r...@quantum.ca> wrote in message news:7l6p6f$lk...@forums.borland.com...

Mike Williams

unread,
Jun 27, 1999, 3:00:00 AM6/27/99
to
> You're taking their function for granted. All I'm asking you to do is to
> think about the array I wrote previously. Or better yet, tell me if the
year
> 2096 is a leap year. If it is, how can it be that 4 years later, the year
> 2100 doesn't get to be a leap one. That would also mean that the year 2004
> IS a leap year. That makes 8 years leap. I'm very sorry but I'm having a
> hard time understanding this.

2096 is a leap year. 2100 is not a leap year. 2104 is a leap year. Yes,
there will be an 8 year gap. The function in Delphi is correct.

Do you understand what leap years are for? There are 365 days, 6 hr, 9 min,
9.5 sec in a year. Because of the fractional part, leap years were added.
Otherwise the seasons would drift away from the calendar. Because 6 hr, 9
min, 9.5 sec is close to 6 hours, or 1/4 of a day, adding an extra day every
four years almost compensates. However, that compensates a little too much,
so it was decided to *not* have a leap year every 100 years. But that did
not quite compensate enough, so consequently the leap year was added back
for years divisible by 400.

-Mike

Ray Lischner

unread,
Jun 28, 1999, 3:00:00 AM6/28/99
to
On Sun, 27 Jun 1999 16:47:39 -0400, "rb" <r...@quantum.ca> wrote:

>Thanks for your responses, though I'd use some brute force to verify this
>calculation:
>
>2000, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68, 72,
>76, 80, 84, 88, 92, 2096 AND 2100.
>
>How do you explain this?

You can write down any numbers you want, but that doesn't change the
fact that 2100 is not a leap year. If you don't believe us, try the
National Institute for Standards and Technology:
http://www.bldrdoc.gov/timefreq/faq/faq.htm#18

--

Wayne Sheffield

unread,
Jun 28, 1999, 3:00:00 AM6/28/99
to
First, let's look at what a leap year is defined as:
Every year evenly divisible by 4, unless it's a century year (evenly
divisible by 100), except for the century years that are evenly
divisible by 400. (All the scientific reasoning for this has been
previously explained in this thread.)

So, lets look at the function to see if it follows the rules:
(AYear mod 4 = 0) // every year evenly divisible by 4
and ((AYear mod 100 <> 0) // year must not be evenly divisible by 100
or (AYear mod 400 = 0)); // unless it is evenly divisible by 400

Your analysis of the function (2nd paragraph below) is 99% correct.
Change it to:

It implies (if I understand this properly) that in order to tell that a
year

is a leap year, the number has to be EVENLY divisible by 4 and has to be
NOT
EVENLY divisible by 100 UNLESS EVENLY divisible by 400.

Now, let's look at some sample dates:
By the definition, we know that a 1996 is a leap year. (Evenly divisible
by 4 and not a century year.)
1997 - 1999 are not leap years (not evenly divisible by 4).
2000 is a leap year - evenly divisible by 4, and since it's a century
year, it must also be evenly divisible by 400.

Now, jump forward a century.
By the definition, 2096 is a leap year.
2097-2099 are not leap years.
2100 is evenly divisible by 4, and it's a century year that is not
evenly divisible by 400. So, it is not a leap year.

When running the above dates through the formula, we get corresponding
answers. So, we have validated the formula as being correct. Since it
has now been validated, we can "take this function for granted".

The key thing to remember is that not every 4th year is a leap year -
there are exceptions.
In a 400 year timeframe, there are a potential 100 leap years. Yet, we
only have 97 leap years during this timeframe. The three century years
that are not divisible by 400 are not leap years, and these are the
"missing" years.

I hope that this clarified it for you. If not, then I'm afraid that
you'll just have to push the "I Believe" button on this issue.

Wayne

(You know, the term "leap year" is probably a bad one - it doesn't
describe what's really going on. In those years, we add an extra day to
the calander (Feb. 29th))

>function TCalendar.IsLeapYear(AYear: Integer): Boolean;
>begin
> Result := (AYear mod 4 = 0) and ((AYear mod 100 <> 0) or (AYear mod 400 =
>0));
>end;

>It implies (if I understand this properly) that in order to tell that a year


>is a leap year, the number has to be divisible by 4 and has to be either NOT
>divisible by 100 but divisible by 400.

rb wrote:
>
> You're right, IsLeapYear was taken from control.pas as I said in my first
> message.
>
> > >

> > >2000, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68,
> 72,
> > >76, 80, 84, 88, 92, 2096 AND 2100.
> > >
> > >How do you explain this?
> >

> > Explain what? 2100 is divisible by 4 and by 100, but NOT divisible by 400,
> > so it's NOT a leap year. That's the rule. The calculation you saw is
>

> Here you go again. You're taking their function for granted. All I'm asking


> you to do is to think about the array I wrote previously. Or better yet,
> tell me if the year 2096 is a leap year. If it is, how can it be that 4
> years later, the year 2100 doesn't get to be a leap one. That would also
> mean that the year 2004 IS a leap year. That makes 8 years leap. I'm very
> sorry but I'm having a hard time understanding this.
>

> rb

Chris Roberts

unread,
Jun 28, 1999, 3:00:00 AM6/28/99
to
"rb" <r...@quantum.ca> wrote:

>> National Institute for Standards and Technology:
>> http://www.bldrdoc.gov/timefreq/faq/faq.htm#18

>You're taking their function for granted.

Whose function / definition do you want? There are some things that you
learnt in infant / primary school which you find are not strictly
correct. You are not taught the finer details at that time since it
would be too complex. Sometimes the teacher is just plain wrong as
well.
This is why leap years have become part of the Year2000 date handling
problem.

Regards,
Chris Roberts

Tom Fosdick

unread,
Jun 28, 1999, 3:00:00 AM6/28/99
to

Wayne Niddery (TeamB) <winw...@chaffhome.com> wrote in message
news:7l6fa1$l1...@forums.borland.com...
...

> Explain what? 2100 is divisible by 4 and by 100, but NOT divisible by 400,
> so it's NOT a leap year.
unless it's divisible by 4000 (the latest correction added to the
defintion).


Ray Lischner

unread,
Jun 29, 1999, 3:00:00 AM6/29/99
to
On Mon, 28 Jun 1999 14:01:21 -0700, "Tom Fosdick" <trfo...@usa.net>
wrote:

>> Explain what? 2100 is divisible by 4 and by 100, but NOT divisible by 400,
>> so it's NOT a leap year.
>unless it's divisible by 4000 (the latest correction added to the
>defintion).

Start fixing those Y4K bugs now!
--
Ray Lischner, co-author of Shakespeare for Dummies
http://www.bardware.com

Timo van Noppen

unread,
Jun 29, 1999, 3:00:00 AM6/29/99
to
After reading all your not-believing stuff and can't wait till you question
the 1+1=2 theory.

Timo

rb <r...@quantum.ca> schreef in berichtnieuws
7l6p6f$lk...@forums.borland.com...


>
> Ray Lischner <delphi.at.te...@nospam.com> wrote in message
> news:3777ba32...@forums.inprise.com...

> > On Sun, 27 Jun 1999 16:47:39 -0400, "rb" <r...@quantum.ca> wrote:
> >
> > >Thanks for your responses, though I'd use some brute force to verify
this
> > >calculation:
> > >

> > >2000, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68,
> 72,
> > >76, 80, 84, 88, 92, 2096 AND 2100.
> > >
> > >How do you explain this?
> >

> > You can write down any numbers you want, but that doesn't change the
> > fact that 2100 is not a leap year. If you don't believe us, try the

> > National Institute for Standards and Technology:
> > http://www.bldrdoc.gov/timefreq/faq/faq.htm#18
> >

> That's great. I've replied to the other guy with the same theory:
>

Larry Killen

unread,
Jun 29, 1999, 3:00:00 AM6/29/99
to
You right, it is a stupid question.

Leap Year is a Man Made correction factor because the universe is not tuned
to our calendar. Even with every fourth year being a correction for the 1/4
day lose suffered each preceding year, our calendar still gets out of kilter
every 4 centuries or so. We kind of overshoot fixing it and have to
re-adjust.

If you don't like it, make a better mouse-trap, 'er I mean wristwatch. Or
don't write applications that'll be around in year 2400.

--
Larry Killen, M.S.
Software Engineer
TRW Systems Integration Group
rb <r...@quantum.ca> wrote in message news:7l6p4a$lk...@forums.borland.com...


> You're right, IsLeapYear was taken from control.pas as I said in my first
> message.
>
> > >

> > >2000, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48, 52, 56, 60, 64, 68,
> 72,
> > >76, 80, 84, 88, 92, 2096 AND 2100.
> > >
> > >How do you explain this?
> >

> > Explain what? 2100 is divisible by 4 and by 100, but NOT divisible by
400,

> > so it's NOT a leap year. That's the rule. The calculation you saw is
>

> Here you go again. You're taking their function for granted. All I'm

Mike Williams

unread,
Jun 29, 1999, 3:00:00 AM6/29/99
to
> If you don't like it, make a better mouse-trap, 'er I mean wristwatch.

I seem to recall that the solid rocket boosters for the space shuttle were
test fired while mounted horizontally on the ground. All we need is enough
of them ... <g>

-Mike

David Thomas

unread,
Jun 30, 1999, 3:00:00 AM6/30/99
to
If you really want to know why the leap years seem wrong... read this...
http://www.gi.alaska.edu/ScienceForum/ASF12/1272.html

The 'wrong' ones were sanctioned by a Pope Gregory back in 1582 so for this
problem I suppose you would be justified if you just blamed God!

David Thomas
da...@diespam.supporthq.com

Tim Roberts

unread,
Jul 1, 1999, 3:00:00 AM7/1/99
to
"rb" <r...@quantum.ca> wrote:

>Here you go again. You're taking their function for granted. All I'm asking
>you to do is to think about the array I wrote previously. Or better yet,
>tell me if the year 2096 is a leap year. If it is, how can it be that 4
>years later, the year 2100 doesn't get to be a leap one. That would also
>mean that the year 2004 IS a leap year. That makes 8 years leap. I'm very
>sorry but I'm having a hard time understanding this.

This has already occurred, by the way: 1900 also was NOT a leap year, even
though 1896 and 1904 were. Of course, there weren't nearly as many people
reading newsgroups at that time.

RB, you seem to have convinced yourself that February 29 always comes
exactly once in every 4 years, no more, no less. That isn't so. Once you
divest yourself of that incorrect notion, you should be fine.

- Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc

rb

unread,
Jul 3, 1999, 3:00:00 AM7/3/99
to
Larry,

You're one hell of funny guy. I would suggest though you should choose your
words more carefully. Making fun of people's questions hasn't been the way
people in IT communicate among themselves.

rb


rb

unread,
Jul 3, 1999, 3:00:00 AM7/3/99
to
>
> >You're taking their function for granted.
>
> Whose function / definition do you want? There are some things that you
> learnt in infant / primary school which you find are not strictly
> correct. You are not taught the finer details at that time since it
> would be too complex.

Yes brainstormer, you're absolutely right. However, if you were alive 400+
years ago you would be giving me this attitude on how Earth is flat and is a
center of the universe.

But I guess, you've always been a good boy a did what other tell you - no
questions asked, ha?

rb

rb

unread,
Jul 3, 1999, 3:00:00 AM7/3/99
to
Thank you all for your responses. Well, there were one or two know-it-all
pricks, but I guess that's why this world is so interesting....

Thanks.

rb

0 new messages