1: <?php
2:
3: /**
4: * This file is part of the "dibi" - smart database abstraction layer.
5: *
6: * Copyright (c) 2005, 2010 David Grudl (http://davidgrudl.com)
7: *
8: * This source file is subject to the "dibi license", and/or
9: * GPL license. For more information please see http://dibiphp.com
10: * @package dibi
11: */
12:
13:
14:
15: /**
16: * DateTime with serialization and timestamp support for PHP 5.2.
17: *
18: * @author David Grudl
19: */
20: class DibiDateTime 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(date('Y-m-d H:i:s', $timestamp), new DateTimeZone($this->getTimezone()->getName())); // getTimeZone() crashes in PHP 5.2.6
49: }
50:
51: }
52: