Re: Date_Calc::isValidDate

From: Date: Tue, 11 Jun 2002 14:16:21 +0000
Subject: Re: Date_Calc::isValidDate
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-6925@lists.php.net to get a copy of this message
> Hello, > > Please find a may easier DateCalc::isValidDate method : > > function isValidDate($day, $month, $year) > { > if($year < 0 || $year > 9999) > return false; > if(!checkdate($day,$month,$year)) > return false; > > return true; > } // end func isValidDate > > I just remove regexp and months checks and use the native php function checkdate. I kept the year check, checkdate works with years between 1 and 32767, a little wide for an 4 digits year ;). > > any comment ? (->commit) Of course go for it. Btw we could also remove the use of Data_Cacl::checkDate() and use the php one. I'd use that to speed up a little the function: if (isset($day) && isset($month) && isset($year)) { if (!check_date($day, $month, $year)) { return false; } if ($min || $max) { include_once 'Date/Calc.php'; if ($min && (Date_Calc::compareDates($day, $month, $year, $min[0], $min[1], $min[2]) < 0)) { return false; } if ($max && (Date_Calc::compareDates($day, $month, $year, $max[0], $max[1], $max[2]) > 0)) { return false; } } } Sorry I don't have access to my system now, I'll commit it later if you don't do it before. Tomas V.V.Cox PS.- BTW Nice thing the test+fixes you commited :-) ------------------ Idecnet Correo-Web

« previous php.pear.dev (#6925) next »