Re: perl leap year function?
- To: Corey Popelier <firstname.lastname@example.org>
- Cc: Aaron Van Couwenberghe <email@example.com>, firstname.lastname@example.org
- Subject: Re: perl leap year function?
- From: Matthias Murra <Matt.Murra@gmx.de>
- Date: Wed, 01 Sep 1999 11:27:26 +0200
- Message-id: <22.214.171.124.19990901112726.04945e10@ganymed>
- In-reply-to: <Pine.LNX.email@example.com om.au>
- References: <19990901005541.F2668@localhost>
>function isLeapYear(year as int) as boolean
> if remainder(year div 4) = 0 then
> return true
> else return false
>I realise this isnt the only condition (theres something fishy about years
>divisible by 400 from memory) but it would do the trick.
The "fishy" part is that years divisible by 100 aren't leap years,
whereas those divisible by 400 are. So 1700, 1800 and 1900 weren't
leap years, but Y2K will be.
>Of course, hardcoding the next few will tide you over for what is most
>likely enough time, im just a sucker for flexible code.
In that case, I suggest enhancing the above pseudo code as follows: :-)
function isLeapYear(year as int) as boolean
if ((remainder(year div 400) = 0) or (remainder(year div 100) <> 0 and
remainder(year div 4) = 0)) then
else return false