sub dateCheck {
my $date = @{{@_}}{qw/date/};
my $err = '0';
if ($date) {
my $year = substr($date,0,4);
my $month = substr($date,4,2);
my $day = substr($date,6,2);
my %month;
$month{'01'} = "January";
$month{'02'} = "February";
$month{'03'} = "March";
$month{'04'} = "April";
$month{'05'} = "May";
$month{'06'} = "June";
$month{'07'} = "July";
$month{'08'} = "August";
$month{'09'} = "September";
$month{'10'} = "October";
$month{'11'} = "November";
$month{'12'} = "December";
my $errDate = "The date you supplied: $month{$month} $day, $year";
if (substr($date,7,1) eq "") {
$err="The date you supplied does not contain enough digits!";
}
elsif (($year < 1900)||($year > 2100)) {
$err="$errDate, did not contain a valid year!";
}
elsif (($month < 1)||($month > 12)) {
$err="$errDate, did not contain a valid month!
";
}
elsif (($day < 1)||($day > 31)) {
$err="$errDate, did not contain a valid day!";
}
elsif ("$month" eq "02") {
my $leap = ($year-2000) % 4;
if ($leap == 0) {
if ($day > 29) {
$err="$errDate, does not exist!
There are only 29 days in $month{$month} $year.";
}
}
elsif ($day > 28) {
$err="$errDate, does not exist!
There are only 28 days in $month{$month} $year.";
}
}
elsif ($month < 8) {
if (($month % 2 == 0)&&($day > 30)) {
$err="$errDate, does not exist!
There are only 30 days in $month{$month}.";
}
}
elsif ($month > 8) {
if (($month % 2 == 1)&&($day > 30)) {
$err="$errDate, does not exist!
There are only 30 days in $month{$month}..";
}
}
}
return $err;
}