in reply to RE: simple stupid time question
in thread simple stupid time question
Also, you declare my $days = 0 but you don't use it.if ($month == 2) { if ( ( $year % 4 == 0 ) # normal leap year && ( ( $year % 100 != 0 ) # century year || ( $year % 400 == 0 ) # leap century ) ) { return 29; } }
Update: All those parens are ugly, how about:
That works thanks to short circuitry and precedence. (yeah I could remove the 0 != part, but I wanted to retain explicit readability.)if( 2 == $month ) { return 29 if 0 == $year % 4 and 0 != $year % 100 or 0 == $year % 400; }
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.
|
|---|