Board index » delphi » 1 stupid question about Leap Year

1 stupid question about Leap Year

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.

Re:1 stupid question about Leap Year

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

Quote

> I'm sort of unclear how to calculate which year is a leap year. This is a
> function from calendar.pas (samples).
> Am I missing something here? Is 25 x 4 not 100 any more?

Re:1 stupid question about Leap Year

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

Re:1 stupid question about Leap Year

Quote
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]

Quote
>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!
=================================================================

Re:1 stupid question about Leap Year

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?

Re:1 stupid question about Leap Year

Quote
rb wrote in message <7l62d0\$l...@forums.borland.com>...

>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?

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

Re:1 stupid question about Leap Year

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

Quote

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

Re:1 stupid question about Leap Year

Quote
Ray Lischner <delphi.at.tempest-sw....@nospam.com> wrote in message

news:3777ba32.5356622@forums.inprise.com...
Quote
> 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:

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

Re:1 stupid question about Leap Year

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

Quote
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)
--

Re:1 stupid question about Leap Year

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

Quote
rb <r...@quantum.ca> wrote in message news:7l6p6f\$lkq1@forums.borland.com...
> 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.

Re:1 stupid question about Leap Year

Quote
> 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

Re:1 stupid question about Leap Year

Quote
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

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

Re:1 stupid question about Leap Year

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))

Quote
>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

Re:1 stupid question about Leap Year

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

Re:1 stupid question about Leap Year

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

Quote
> 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).
Go to page: [1] [2]