Source for file DateTime53.php

Documentation is available at DateTime53.php

  1. 1: <?php
  2. 2:  
  3. 3: /**
  4. 4:  * Nette Framework
  5. 5:  *
  6. 6:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  7. 7:  * @license    http://nettephp.com/license  Nette license
  8. 8:  * @link       http://nettephp.com
  9. 9:  * @category   Nette
  10. 10:  * @package    Nette
  11. 11:  */
  12. 12:  
  13. 13: // no namespace
  14. 14:  
  15. 15:  
  16. 16:  
  17. 17: /**
  18. 18:  * DateTime with serialization and timestamp support for PHP 5.2.
  19. 19:  *
  20. 20:  * @copyright  Copyright (c) 2004, 2010 David Grudl
  21. 21:  * @package    Nette
  22. 22:  */
  23. 23: class DateTime53 extends DateTime
  24. 24: {
  25. 25:     
  26. 26:     public function __sleep()
  27. 27:     {
  28. 28:         $this->fix array($this->format('Y-m-d H:i:s')$this->getTimezone()->getName());
  29. 29:         return array('fix');
  30. 30:     }
  31. 31:  
  32. 32:  
  33. 33:  
  34. 34:     public function __wakeup()
  35. 35:     {
  36. 36:         $this->__construct($this->fix[0]new DateTimeZone($this->fix[1]));
  37. 37:         unset($this->fix);
  38. 38:     }
  39. 39:  
  40. 40:  
  41. 41:  
  42. 42:     public function getTimestamp()
  43. 43:     {
  44. 44:         return (int) $this->format('U');
  45. 45:     }
  46. 46:  
  47. 47:  
  48. 48:  
  49. 49:     public function setTimestamp($timestamp)
  50. 50:     {
  51. 51:         return $this->__construct(gmdate('Y-m-d H:i:s'$timestamp)new DateTimeZone($this->getTimezone()->getName()))// simply getTimezone() crashes in PHP 5.2.6
  52. 52:     }
  53. 53:     
  54. 54: }