Your leap year code is still wrong.
It should be:
if ($month == 2)
{
if ( ( $year % 4 == 0 ) # normal leap year
&& ( ( $year % 100 != 0 ) # century year
|| ( $year % 400 == 0 ) # leap century
)
)
{
return 29;
}
}
Also, you declare my $days = 0 but you don't use it.
Update: All those parens are ugly, how about:
if( 2 == $month )
{
return 29 if 0 == $year % 4 and 0 != $year % 100
or 0 == $year % 400;
}
That works thanks to short circuitry and precedence. (yeah I could remove the 0 != part, but I wanted to retain explicit readability.)
I think the leap year formula has become a frequently asked question, so I posted the answer here as well.
Update: Chromatic's code will now work. It a slightly different way to look at it, using if and unless, but it works. |