1
|
|
|
<?php |
2
|
|
|
namespace EventEspresso\core\domain\entities; |
3
|
|
|
|
4
|
|
|
if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
5
|
|
|
exit( 'No direct script access allowed' ); |
6
|
|
|
} |
7
|
|
|
|
8
|
|
|
|
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* Class DbSafeDateTime |
12
|
|
|
* Some versions of PHP do bad things when you try to serialize a DateTime object for storage. |
13
|
|
|
* This DateTime class extension can be safely serialized and unserialized, |
14
|
|
|
* because the only data it stores is a string containing all o fits relevant details |
15
|
|
|
* |
16
|
|
|
* @package Event Espresso |
17
|
|
|
* @author Brent Christensen |
18
|
|
|
* @since $VID:$ |
19
|
|
|
*/ |
20
|
|
|
class DbSafeDateTime extends \DateTime { |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @type string db_safe_timestamp_format |
24
|
|
|
*/ |
25
|
|
|
const db_safe_timestamp_format = 'Y-m-d H:i:s O e'; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* DateTime object converted to a string that includes the date, time, UTC offset, and timezone identifier |
29
|
|
|
* |
30
|
|
|
* @type string $_datetime_string |
31
|
|
|
*/ |
32
|
|
|
protected $_datetime_string = ''; |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
|
36
|
|
|
public function __toString() { |
37
|
|
|
return $this->format( DbSafeDateTime::db_safe_timestamp_format ); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
|
41
|
|
|
|
42
|
|
|
public function __sleep() { |
43
|
|
|
$this->_datetime_string = $this->format( DbSafeDateTime::db_safe_timestamp_format ); |
44
|
|
|
return array( '_datetime_string' ); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
|
49
|
|
|
public function __wakeup() { |
50
|
|
|
$date = \DateTime::createFromFormat( DbSafeDateTime::db_safe_timestamp_format, $this->_datetime_string ); |
51
|
|
|
$this->__construct( |
52
|
|
|
$date->format( \EE_Datetime_Field::mysql_timestamp_format), |
53
|
|
|
new \DateTimeZone( $date->format( 'e' ) ) |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
|
58
|
|
|
} |
59
|
|
|
// End of file DbSafeDateTime.php |
60
|
|
|
// Location: EventEspresso\core\domain\entities/DbSafeDateTime.php |