1
0
mirror of https://github.com/dg/dibi.git synced 2025-10-24 19:26:10 +02:00

DateTime53 renamed to DibiDateTime

This commit is contained in:
David Grudl
2010-10-06 16:02:20 +02:00
parent 90592929ec
commit 8d6639fa3c
5 changed files with 25 additions and 30 deletions

View File

@@ -0,0 +1,51 @@
<?php
/**
* This file is part of the "dibi" - smart database abstraction layer.
*
* Copyright (c) 2005, 2010 David Grudl (http://davidgrudl.com)
*
* This source file is subject to the "dibi license", and/or
* GPL license. For more information please see http://dibiphp.com
* @package dibi
*/
/**
* DateTime with serialization and timestamp support for PHP 5.2.
*
* @author David Grudl
*/
class DibiDateTime extends DateTime
{
public function __sleep()
{
$this->fix = array($this->format('Y-m-d H:i:s'), $this->getTimezone()->getName());
return array('fix');
}
public function __wakeup()
{
$this->__construct($this->fix[0], new DateTimeZone($this->fix[1]));
unset($this->fix);
}
public function getTimestamp()
{
return (int) $this->format('U');
}
public function setTimestamp($timestamp)
{
return $this->__construct(date('Y-m-d H:i:s', $timestamp), new DateTimeZone($this->getTimezone()->getName())); // getTimeZone() crashes in PHP 5.2.6
}
}

View File

@@ -592,7 +592,7 @@ class DibiResult extends DibiObject implements IDataSource
return NULL;
} elseif ($this->dateFormat === '') { // return DateTime object (default)
return new DateTime53(is_numeric($value) ? date('Y-m-d H:i:s', $value) : $value);
return new DibiDateTime(is_numeric($value) ? date('Y-m-d H:i:s', $value) : $value);
} elseif ($this->dateFormat === 'U') { // return timestamp
return is_numeric($value) ? (int) $value : strtotime($value);
@@ -601,7 +601,7 @@ class DibiResult extends DibiObject implements IDataSource
return date($this->dateFormat, $value);
} else {
$value = new DateTime53($value);
$value = new DibiDateTime($value);
return $value->format($this->dateFormat);
}

View File

@@ -46,7 +46,7 @@ class DibiRow implements ArrayAccess, IteratorAggregate, Countable
if ((int) $time === 0) { // '', NULL, FALSE, '0000-00-00', ...
return NULL;
}
$dt = new DateTime53(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time);
$dt = new DibiDateTime(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time);
return $format === NULL ? $dt : $dt->format($format);
}