diff --git a/dibi/Nette/DateTime53.php b/dibi/Nette/DateTime53.php new file mode 100644 index 00000000..65b6a4c3 --- /dev/null +++ b/dibi/Nette/DateTime53.php @@ -0,0 +1,54 @@ +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 + } + +} diff --git a/dibi/dibi.php b/dibi/dibi.php index 14c57ece..8fe08d74 100644 --- a/dibi/dibi.php +++ b/dibi/dibi.php @@ -60,12 +60,16 @@ if (!interface_exists(/*Nette\*/'IDebuggable', FALSE)) { require_once dirname(__FILE__) . '/Nette/IDebuggable.php'; } +if (!class_exists('DateTime53', FALSE)) { + require_once dirname(__FILE__) . '/Nette/DateTime53.php'; +} + /** * Back-compatibility */ -class DibiVariable extends DateTime +class DibiVariable extends DateTime53 { function __construct($val) { @@ -587,7 +591,7 @@ class dibi */ public static function datetime($time = NULL) { - return new DateTime(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time); + return new DateTime53(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time); } @@ -597,7 +601,7 @@ class dibi */ public static function date($date = NULL) { - return new DateTime(is_numeric($date) ? date('Y-m-d', $date) : $date); + return new DateTime53(is_numeric($date) ? date('Y-m-d', $date) : $date); } diff --git a/dibi/libs/DibiResult.php b/dibi/libs/DibiResult.php index 683510aa..30607d57 100644 --- a/dibi/libs/DibiResult.php +++ b/dibi/libs/DibiResult.php @@ -623,13 +623,13 @@ class DibiResult extends DibiObject implements IDataSource return is_numeric($value) ? (int) $value : strtotime($value); } elseif ($format === TRUE) { // return DateTime object - return new DateTime(is_numeric($value) ? date('Y-m-d H:i:s', $value) : $value); + return new DateTime53(is_numeric($value) ? date('Y-m-d H:i:s', $value) : $value); } elseif (is_numeric($value)) { // single timestamp return date($format, $value); } else { - $value = new DateTime($value); + $value = new DateTime53($value); return $value->format($format); } diff --git a/dibi/libs/DibiRow.php b/dibi/libs/DibiRow.php index dd0b5244..854c624b 100644 --- a/dibi/libs/DibiRow.php +++ b/dibi/libs/DibiRow.php @@ -47,13 +47,13 @@ class DibiRow extends ArrayObject return is_numeric($time) ? (int) $time : strtotime($time); } elseif ($format === TRUE) { // return DateTime object - return new DateTime(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time); + return new DateTime53(is_numeric($time) ? date('Y-m-d H:i:s', $time) : $time); } elseif (is_numeric($time)) { // single timestamp return date($format, $time); } else { - $time = new DateTime($time); + $time = new DateTime53($time); return $time->format($format); } }