Last active
August 29, 2015 13:57
-
-
Save chandeeland/9817516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* DateTimeWrapper | |
* | |
* This class exists because you cannot modify the microseconds of a native PHP 5.5 | |
* DateTime Object without creating a whole new instance. | |
* | |
* Additionally, this class allows you to serialize Datetime Objects without losing | |
* the microseconds. | |
* | |
* @copyright 2014 Mshanken Communications | |
* @author David Chan <[email protected]> | |
* @license BSD-3 | |
*/ | |
class DateTimeWrapper | |
{ | |
private $datetime = null; | |
private $cold = null; | |
public function __construct(DateTime $datetime) | |
{ | |
$this->datetime = $datetime; | |
} | |
public function __call($method, $params) | |
{ | |
return call_user_func_array(array($this->datetime, $method), $params); | |
} | |
public static function __callStatic($method, $params) | |
{ | |
return forward_static_call_array(array($this->datetime, $method), $params); | |
} | |
public function __sleep() | |
{ | |
$this->cold = $this->datetime->format('Y-m-d G:i:s.u'); | |
// unset($this->datetime); | |
return array('cold'); | |
} | |
public function __wakeup() | |
{ | |
$this->__construct(DateTime::createFromFormat('Y-m-d G:i:s.u', $this->cold)); | |
} | |
public function getDateTime() | |
{ | |
return $this->datetime; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there any reason for using
G
instead ofH
for hours?