Problems with Date.php 1.3.1 beta
| From: | Jan Jonas | Date: | Mon, 04 Aug 2003 09:49:22 +0000 |
| Subject: | Problems with Date.php 1.3.1 beta | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-19236@lists.php.net to get a copy of this message | ||
Hello,
after updating PEAR, I get a new version of Date.php. But I have some
Problems to use it.
This is the constructor of the class:
function Date($date = null)
{
$this->tz = Date_TimeZone::getDefault();
if (is_null($date)) {
$this->setDate(date('Y-m-d H:i:s'));
} elseif (is_object($date) && (get_class($date) == 'date')) {
$this->copy($date);
} elseif (preg_match('/\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/',
$date)) {
$this->setDate($date);
} elseif (preg_match('/\d{14}/',$date)) {
$this->setDate($date,DATE_FORMAT_TIMESTAMP);
} elseif (preg_match('/\d{4}-\d{2}-\d{2}/', $date)) {
$this->setDate($date.' 00:00:00');
} elseif (preg_match('/\d{8}/',$date)) {
$this->setDate($date.'000000',DATE_FORMAT_TIMESTAMP);
} else {
$this->setDate($date,DATE_FORMAT_UNIXTIME);
}
}
If I use the class like this:
$date = new Date(time());
The Date in my Object $date is not right. In my Opinion the Problem is,
that time() returns an Unixtimestamp (10 numbers) and the "elseif
(preg_match('/\d{8}/',$date))" condition in the constructor is true, so
that setDate is called with wrong parameters: DATE_FORMAT_TIMESTAMP
instead of DATE_FORMAT_UNIXTIME. The preg_match found the first 8 number
in my unixtimpstamp and so the condition ist right. The last
setDate($date,DATE_FORMAT_UNIXTIME) will never called.
If I comment the lines
elseif (preg_match('/\d{8}/',$date)) {
$this->setDate($date.'000000',DATE_FORMAT_TIMESTAMP);
}
out the class will work fine.
Jan