my @monthDays= qw( 31 28 31 30 31 30 31 31 30 31 30 31 );
sub MonthDays {
my $month= shift(@_);
my $year= @_ ? shift(@_) : 1900+(localtime())[5];
if( $year <= 1752 ) {
# Note: Although September 1752 only had 19 days,
# they were numbered 1,2,14..30!
return 19 if 1752 == $year && 9 == $month;
return 29 if 2 == $month && 0 == $year % 4;
} else {
return 29 if 2 == $month and
0 == $year%4 && 0 == $year%100 || 0 == $year%400;
}
return $monthDays[$month-1];
}
This covers Julian and Gregorian dates and uses Julian month lengths even prior to the Julian calendar.