1: <?php
2:
3: /**
4: * This file is part of the Nette Framework.
5: *
6: * Copyright (c) 2004, 2010 David Grudl (http://davidgrudl.com)
7: *
8: * This source file is subject to the "Nette license", and/or
9: * GPL license. For more information please see http://nette.org
10: */
11:
12:
13:
14: /**
15: * DateTime with serialization and timestamp support for PHP 5.2.
16: *
17: * @author David Grudl
18: * @phpversion < 5.3
19: */
20: class DateTime53 extends DateTime
21: {
22:
23: public function __sleep()
24: {
25: $this->fix = array($this->format('Y-m-d H:i:s'), $this->getTimezone()->getName());
26: return array('fix');
27: }
28:
29:
30:
31: public function __wakeup()
32: {
33: $this->__construct($this->fix[0], new DateTimeZone($this->fix[1]));
34: unset($this->fix);
35: }
36:
37:
38:
39: public function getTimestamp()
40: {
41: return (int) $this->format('U');
42: }
43:
44:
45:
46: public function setTimestamp($timestamp)
47: {
48: return $this->__construct(gmdate('Y-m-d H:i:s', $timestamp), new DateTimeZone($this->getTimezone()->getName())); // simply getTimezone() crashes in PHP 5.2.6
49: }
50:
51: }
52: