in reply to simple stupid time question
sub days_in_month { my $month = shift; my $year = shift; my @mdays = qw( 31 28 31 30 31 30 31 31 30 31 30 31 ); if ($month == 2) { if ($year % 4 == 0) { # normal leap year if ($year % 100 == 0) { # century year, not a leap year return 28 unless ($year % 400 == 0); # century AND leap year } return 29; } } return $mdays[$month - 1]; # fudge the index }
Update: Foggy and Adam contributed the current state of (now tested) not-so-bugginess. Seems like I should have actually *looked it up* in my library before I tried to recreate this wheel from memory.
I originally intended this to be straightforward teaching code, but Adam's second snippet is much better.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: RE: simple stupid time question
by Adam (Vicar) on Sep 14, 2000 at 22:45 UTC | |
|
RE: RE: simple stupid time question
by Fastolfe (Vicar) on Sep 14, 2000 at 17:38 UTC | |
by spudzeppelin (Pilgrim) on Sep 14, 2000 at 18:53 UTC |