Re: New package: DB_DataObject_FormBuilder
| From: | Ron McClain | Date: | Sun, 24 Aug 2003 04:22:29 +0000 |
| Subject: | Re: New package: DB_DataObject_FormBuilder | ||
| References: | 1 2 3 4 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-20449@lists.php.net to get a copy of this message | ||
Actually, there's another problem in the same function. If you pass in an array
and $timestamp=true, it still will give back a string.
Here's a working version. It could be done with less elseifs, but because
the && options don't get evaluated past the first one that fails, I think
this is efficient.. i.e., do the simple tests first, make sure checkdate is only called once.
-Ron
function _array2date($date, $timestamp=false)
{
if($timestamp == false && is_array($date) && checkdate($date['M'], $date['d'], $date['Y'])) {
$strDate = $date['Y'].'-'.$date['M'].'-'.$date['d'];
} elseif($timestamp == true && is_array($date) && checkdate($date['M'], $date['d'], $date['Y'])) {
$strDate = strtotime($date['Y'].'-'.$date['M'].'-'.$date['d']);
} elseif($timestamp == true) {
$strDate = time();
} else {
$strDate = date('Y-m-d', time());
}
return $strDate;
}
Ron McClain wrote:
Hi Markus. Finally got some time to look at this. It looks really nice.. been meaning to
write it myself ;)
Anyhow, I think you have a bug. Shouldn't the elseif condition be is_array?
Otherwise, the package looks great. I know I'll make use of it. Just thought I'd point that out.
function _array2date($date, $timestamp=false)
{
if (is_array($date) && checkdate($date['M'], $date['d'], $date['Y'])) {
$strDate = $date['Y'].'-'.$date['M'].'-'.$date['d'];
} elseif (is_int($date) && $timestamp==true) {
--> ^^^^ is_array
$strDate = strtotime($date['Y'].'-'.$date['M'].'-'.$date['d']);
} else {
$strDate = date('Y-m-d', time());
}
return $strDate;
}