Created
August 26, 2009 07:11
-
-
Save lestrrat/175359 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my @last_days = (31, undef, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); | |
sub is_leap_year { | |
my $year = shift; | |
return 0 if $year % 4; | |
return 1 if $year % 100; | |
return 0 if $year % 400; | |
return 1; | |
} | |
sub last_day { | |
my ($year, $month) = @_; | |
if ($month == 2) { | |
if (is_leap_year($year)) { | |
return 29; | |
} else { | |
return 28; | |
} | |
} else { | |
return $last_days[ $month - 1 ]; | |
} | |
} | |
my @days = ( | |
[ 1900, 2 ], | |
[ 2000, 2 ], | |
[ 2009, 8 ], | |
[ 2009, 9 ], | |
); | |
foreach my $set (@days) { | |
print "@$set -> ", last_day(@$set), "\n"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment