1 | <?php |
||
18 | class DbSafeDateTime extends DateTime |
||
19 | { |
||
20 | |||
21 | // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
||
22 | /** |
||
23 | * @type string db_safe_timestamp_format |
||
24 | */ |
||
25 | const db_safe_timestamp_format = 'Y-m-d H:i:s O e'; |
||
26 | // phpcs:enable |
||
27 | |||
28 | // phpcs:disable PSR2.Classes.PropertyDeclaration.Underscore |
||
29 | /** |
||
30 | * DateTime object converted to a string that includes the date, time, UTC offset, and timezone identifier |
||
31 | * |
||
32 | * @type string $_datetime_string |
||
33 | */ |
||
34 | protected $_datetime_string = ''; |
||
35 | |||
36 | /** |
||
37 | * where to write the error log to |
||
38 | * |
||
39 | * @type string $_error_log_dir |
||
40 | */ |
||
41 | protected $_error_log_dir = ''; |
||
42 | // phpcs:enable |
||
43 | |||
44 | |||
45 | /** |
||
46 | * @param string $error_log_dir |
||
47 | */ |
||
48 | public function setErrorLogDir($error_log_dir) |
||
55 | |||
56 | |||
57 | /** |
||
58 | * @return string |
||
59 | */ |
||
60 | public function __toString() |
||
64 | |||
65 | |||
66 | /** |
||
67 | * @return array |
||
68 | */ |
||
69 | public function __sleep() |
||
99 | |||
100 | |||
101 | /** |
||
102 | * if an empty or null value got saved to the db for a datetime, |
||
103 | * then some servers and/or PHP itself will incorrectly convert that date string |
||
104 | * resulting in "-0001-11-30" for the year-month-day. |
||
105 | * see the Notes section |
||
106 | * |
||
107 | * @link http://php.net/manual/en/datetime.formats.date.php |
||
108 | * We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created, |
||
109 | * but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000". |
||
110 | * so we're no better off, but at least things won't go fatal on us. |
||
111 | */ |
||
112 | public function __wakeup() |
||
138 | |||
139 | |||
140 | /** |
||
141 | * Normalizes incoming date string so that it is a bit more stable for use. |
||
142 | * @param string $date_string |
||
143 | * @return string |
||
144 | */ |
||
145 | public static function normalizeInvalidDate($date_string) |
||
153 | |||
154 | |||
155 | /** |
||
156 | * Creates a DbSafeDateTime from ye old DateTime |
||
157 | * |
||
158 | * @param DateTime $datetime |
||
159 | * @return \EventEspresso\core\domain\entities\DbSafeDateTime |
||
160 | */ |
||
161 | public static function createFromDateTime(DateTime $datetime) |
||
168 | |||
169 | |||
170 | /** |
||
171 | * Parse a string into a new DateTime object according to the specified format |
||
172 | * |
||
173 | * @param string $format Format accepted by date(). |
||
174 | * @param string $time String representing the time. |
||
175 | * @param DateTimeZone $timezone A DateTimeZone object representing the desired time zone. |
||
176 | * @return DbSafeDateTime|boolean |
||
177 | * @link https://php.net/manual/en/datetime.createfromformat.php |
||
178 | */ |
||
179 | public static function createFromFormat($format, $time, $timezone = null) |
||
190 | |||
191 | |||
192 | /** |
||
193 | * @param string $message |
||
194 | */ |
||
195 | private function writeToErrorLog($message) |
||
205 | } |
||
206 |