Apache-Voodoo
view release on metacpan or search on metacpan
lib/Apache/Voodoo.pm view on Meta::CPAN
return undef;
}
my $pm = 'NA';
if ($time =~ s/([ap])m$//igo) {
$pm = (lc($1) eq "p")?1:0;
}
my ($h,$m) = split(/:/,$time,2);
if ($m < 0 || $m > 60) { return undef; }
if ($h < 0 || $h > 23) { return undef; }
# 12 am is midnight and 12 pm is noon...I've always hated that.
if ($pm eq '1' && $h < 12) {
$h += 12;
}
elsif ($pm eq '0' && $h == 12) {
$h = 0;
}
return sprintf("%02d:%02d:00",$h,$m);
}
################################################################################
# Misc
################################################################################
# Function: dates_in_order
# Purpose: Make sure end date comes after start date
sub dates_in_order {
my $self = shift;
my $startdate = shift;
my $enddate = shift;
#split off the parts of the date
my ($sm,$sd,$sy) = split("/",$startdate, 3);
my ($em,$ed,$ey) = split("/",$enddate, 3);
#make sure the end date is past the start date
if ($ey < $sy) {
return 0;
}
elsif ($ey == $sy) {
if ($em < $sm) {
return 0;
}
elsif ($em == $sm) {
if ($ed < $sd) {
return 0;
}
}
}
# If we got here we were sucessful
return 1;
}
# Function: validate_date
# Purpose: Check to make sure a date follows the MM/DD/YYYY format and checks the sanity of the numbers passed in
sub validate_date {
my $self = shift;
my $date = shift;
my $check_future = shift;
#Number of days in each month
my %md = (1 => 31,
2 => 29,
3 => 31,
4 => 30,
5 => 31,
6 => 30,
7 => 31,
8 => 31,
9 => 30,
10 => 31,
11 => 30,
12 => 31);
#Split the date up into month day year
my ($m,$d,$y) = split("/",$date, 3);
#Strip off any leading 0s
$m *= 1;
$d *= 1;
$y *= 1;
#If the month isn't within a valid range return
if ($m !~ /^\d+$/ || $m < 1 || $m > 12) {
return 0;
}
#Check to see if the day is valid on leap years
if ($m == 2 && $d == 29) {
unless (($y%4 == 0 && $y%100 != 0) || $y%400 == 0){
return 0;
}
}
#If the day isn't within a valid range return
if ($d !~ /^\d+$/ || $d < 1 || $d > $md{$m}) {
return 0;
}
# make sure the year is four digits
if ($y !~ /^\d+$/ || $y < 1000 || $y > 9999) {
return 0;
}
if ($check_future == 1) {
#Get the local system time
my ($M,$D,$Y) = (localtime(time))[4,3,5];
$M++;
$Y+=1900;
#Make sure the date is in the future
if ($y < $Y) {
return undef;
}
elsif ($y == $Y) {
( run in 1.152 second using v1.01-cache-2.11-cpan-39bf76dae61 )