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