2010-01-14 23:41:37 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2010-10-06 16:02:20 +02:00
|
|
|
* This file is part of the "dibi" - smart database abstraction layer.
|
2010-01-14 23:41:37 +01:00
|
|
|
*
|
2012-01-02 20:24:16 +01:00
|
|
|
* Copyright (c) 2005 David Grudl (http://davidgrudl.com)
|
2010-09-14 18:40:41 +02:00
|
|
|
*
|
2011-02-02 00:33:52 +01:00
|
|
|
* For the full copyright and license information, please view
|
|
|
|
* the file license.txt that was distributed with this source code.
|
2010-01-14 23:41:37 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* DateTime with serialization and timestamp support for PHP 5.2.
|
|
|
|
*
|
2010-09-14 18:40:41 +02:00
|
|
|
* @author David Grudl
|
2012-01-03 04:50:11 +01:00
|
|
|
* @package dibi
|
2010-01-14 23:41:37 +01:00
|
|
|
*/
|
2010-10-06 16:02:20 +02:00
|
|
|
class DibiDateTime extends DateTime
|
2010-01-14 23:41:37 +01:00
|
|
|
{
|
2010-01-23 04:45:59 +01:00
|
|
|
|
2011-01-24 20:47:35 +01:00
|
|
|
public function __construct($time = 'now', DateTimeZone $timezone = NULL)
|
|
|
|
{
|
|
|
|
if (is_numeric($time)) {
|
|
|
|
$time = date('Y-m-d H:i:s', $time);
|
|
|
|
}
|
|
|
|
if ($timezone === NULL) {
|
|
|
|
parent::__construct($time);
|
|
|
|
} else {
|
|
|
|
parent::__construct($time, $timezone);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-01-12 14:59:56 +01:00
|
|
|
public function modifyClone($modify = '')
|
|
|
|
{
|
|
|
|
$dolly = clone($this);
|
|
|
|
return $modify ? $dolly->modify($modify) : $dolly;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function modify($modify)
|
|
|
|
{
|
|
|
|
parent::modify($modify);
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-14 23:41:37 +01:00
|
|
|
public function __sleep()
|
|
|
|
{
|
2013-09-30 01:09:14 +02:00
|
|
|
$zone = $this->getTimezone()->getName();
|
|
|
|
if ($zone[0] === '+') {
|
|
|
|
$this->fix = array($this->format('Y-m-d H:i:sP'));
|
|
|
|
} else {
|
|
|
|
$this->fix = array($this->format('Y-m-d H:i:s'), $zone);
|
|
|
|
}
|
2010-01-14 23:41:37 +01:00
|
|
|
return array('fix');
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function __wakeup()
|
|
|
|
{
|
2013-09-30 01:09:14 +02:00
|
|
|
if (isset($this->fix[1])) {
|
|
|
|
$this->__construct($this->fix[0], new DateTimeZone($this->fix[1]));
|
|
|
|
} else {
|
|
|
|
$this->__construct($this->fix[0]);
|
|
|
|
}
|
2010-01-14 23:41:37 +01:00
|
|
|
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
|
|
|
|
}
|
2010-01-23 04:45:59 +01:00
|
|
|
|
2012-01-12 14:59:56 +01:00
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return $this->format('Y-m-d H:i:s');
|
|
|
|
}
|
|
|
|
|
2010-01-14 23:41:37 +01:00
|
|
|
}
|