| @@ -6,295 +6,295 @@ | ||
| 6 | 6 | use DateTimeZone; |
| 7 | 7 | |
| 8 | 8 | final class DateTimeHelper |
| 9 | 9 | { |
| 10 | - private $_dateFormat; | |
| 11 | - private $_timeFormat; | |
| 12 | - private $_timezone; | |
| 13 | - private $_currentTime; | |
| 14 | - private $_currentFormat; | |
| 10 | + private $_dateFormat; | |
| 11 | + private $_timeFormat; | |
| 12 | + private $_timezone; | |
| 13 | + private $_currentTime; | |
| 14 | + private $_currentFormat; | |
| 15 | 15 | |
| 16 | - public function __construct() | |
| 17 | - { | |
| 18 | - $this->_dateFormat = get_option('date_format'); | |
| 19 | - $this->_timeFormat = get_option('time_format'); | |
| 20 | - $this->_timezone = self::wp_timezone(); | |
| 21 | - $this->_currentTime = current_time("mysql"); | |
| 22 | - $this->_currentFormat = 'Y-m-d H:i:s'; | |
| 16 | + public function __construct() | |
| 17 | + { | |
| 18 | + $this->_dateFormat = get_option('date_format'); | |
| 19 | + $this->_timeFormat = get_option('time_format'); | |
| 20 | + $this->_timezone = self::wp_timezone(); | |
| 21 | + $this->_currentTime = current_time('mysql'); | |
| 22 | + $this->_currentFormat = 'Y-m-d H:i:s'; | |
| 23 | + } | |
| 24 | + | |
| 25 | + public function getDate($date = null, $currentFormat = null, $currentTZ = null, $expectedFormat = null, $expectedTZ = null) | |
| 26 | + { | |
| 27 | + if (is_null($date)) { | |
| 28 | + $date = $this->_currentTime; | |
| 29 | + $currentFormat = $this->_currentFormat; | |
| 30 | + $currentTZ = $this->_timezone; | |
| 23 | 31 | } |
| 24 | 32 | |
| 25 | - public function getDate($date = null, $currentFormat = null, $currentTZ = null, $expectedFormat = null, $expectedTZ = null) | |
| 26 | - { | |
| 27 | - if (is_null($date)) { | |
| 28 | - $date = $this->_currentTime; | |
| 29 | - $currentFormat = $this->_currentFormat; | |
| 30 | - $currentTZ = $this->_timezone; | |
| 31 | - } | |
| 33 | + $currentFormat = is_null($currentFormat) ? $this->_currentFormat : $currentFormat; | |
| 34 | + $currentTZ = is_null($currentTZ) ? $this->_timezone : $currentTZ; | |
| 35 | + $expectedFormat = is_null($expectedFormat) ? $this->_dateFormat : $expectedFormat; | |
| 36 | + $expectedTZ = is_null($expectedTZ) ? $this->_timezone : $expectedTZ; | |
| 32 | 37 | |
| 33 | - $currentFormat = is_null($currentFormat) ? $this->_currentFormat : $currentFormat; | |
| 34 | - $currentTZ = is_null($currentTZ) ? $this->_timezone : $currentTZ; | |
| 35 | - $expectedFormat = is_null($expectedFormat) ? $this->_dateFormat : $expectedFormat; | |
| 36 | - $expectedTZ = is_null($expectedTZ) ? $this->_timezone : $expectedTZ; | |
| 38 | + return $this->getFormated($date, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ); | |
| 39 | + } | |
| 37 | 40 | |
| 38 | - return $this->getFormated($date, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ); | |
| 41 | + public function getTime($date = null, $currentFormat = null, $currentTZ = null, $expectedFormat = null, $expectedTZ = null) | |
| 42 | + { | |
| 43 | + if (is_null($date)) { | |
| 44 | + $date = $this->_currentTime; | |
| 45 | + $currentFormat = $this->_currentFormat; | |
| 46 | + $currentTZ = $this->_timezone; | |
| 39 | 47 | } |
| 40 | 48 | |
| 41 | - public function getTime($date = null, $currentFormat = null, $currentTZ = null, $expectedFormat = null, $expectedTZ = null) | |
| 42 | - { | |
| 43 | - if (is_null($date)) { | |
| 44 | - $date = $this->_currentTime; | |
| 45 | - $currentFormat = $this->_currentFormat; | |
| 46 | - $currentTZ = $this->_timezone; | |
| 47 | - } | |
| 49 | + $currentFormat = is_null($currentFormat) ? $this->_currentFormat : $currentFormat; | |
| 50 | + $currentTZ = is_null($currentTZ) ? $this->_timezone : $currentTZ; | |
| 51 | + $expectedFormat = is_null($expectedFormat) ? $this->_timeFormat : $expectedFormat; | |
| 52 | + $expectedTZ = is_null($expectedTZ) ? $this->_timezone : $expectedTZ; | |
| 48 | 53 | |
| 49 | - $currentFormat = is_null($currentFormat) ? $this->_currentFormat : $currentFormat; | |
| 50 | - $currentTZ = is_null($currentTZ) ? $this->_timezone : $currentTZ; | |
| 51 | - $expectedFormat = is_null($expectedFormat) ? $this->_timeFormat : $expectedFormat; | |
| 52 | - $expectedTZ = is_null($expectedTZ) ? $this->_timezone : $expectedTZ; | |
| 54 | + return $this->getFormated($date, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ); | |
| 55 | + } | |
| 53 | 56 | |
| 54 | - return $this->getFormated($date, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ); | |
| 57 | + public function getDay($nameType, $date = null, $currentFormat = null, $currentTZ = null, $expectedTZ = null) | |
| 58 | + { | |
| 59 | + if (is_null($date)) { | |
| 60 | + $date = $this->_currentTime; | |
| 61 | + $currentFormat = $this->_currentFormat; | |
| 62 | + $currentTZ = $this->_timezone; | |
| 55 | 63 | } |
| 56 | 64 | |
| 57 | - public function getDay($nameType, $date = null, $currentFormat = null, $currentTZ = null, $expectedTZ = null) | |
| 58 | - { | |
| 59 | - if (is_null($date)) { | |
| 60 | - $date = $this->_currentTime; | |
| 61 | - $currentFormat = $this->_currentFormat; | |
| 62 | - $currentTZ = $this->_timezone; | |
| 63 | - } | |
| 65 | + $currentFormat = is_null($currentFormat) ? $this->_currentFormat : $currentFormat; | |
| 66 | + $currentTZ = is_null($currentTZ) ? $this->_timezone : $currentTZ; | |
| 67 | + $expectedTZ = is_null($expectedTZ) ? $this->_timezone : $expectedTZ; | |
| 64 | 68 | |
| 65 | - $currentFormat = is_null($currentFormat) ? $this->_currentFormat : $currentFormat; | |
| 66 | - $currentTZ = is_null($currentTZ) ? $this->_timezone : $currentTZ; | |
| 67 | - $expectedTZ = is_null($expectedTZ) ? $this->_timezone : $expectedTZ; | |
| 69 | + switch ($nameType) { | |
| 70 | + case 'numeric-with-leading': | |
| 71 | + $expectedFormat = 'd'; | |
| 72 | + break; | |
| 68 | 73 | |
| 69 | - switch ($nameType) { | |
| 70 | - case 'numeric-with-leading': | |
| 71 | - $expectedFormat = 'd'; | |
| 72 | - break; | |
| 74 | + case 'numeric-without-leading': | |
| 75 | + $expectedFormat = 'j'; | |
| 76 | + break; | |
| 73 | 77 | |
| 74 | - case 'numeric-without-leading': | |
| 75 | - $expectedFormat = 'j'; | |
| 76 | - break; | |
| 78 | + case 'short-name': | |
| 79 | + $expectedFormat = 'D'; | |
| 80 | + break; | |
| 77 | 81 | |
| 78 | - case 'short-name': | |
| 79 | - $expectedFormat = 'D'; | |
| 80 | - break; | |
| 82 | + case 'full-name': | |
| 83 | + $expectedFormat = 'l'; | |
| 84 | + break; | |
| 81 | 85 | |
| 82 | - case 'full-name': | |
| 83 | - $expectedFormat = 'l'; | |
| 84 | - break; | |
| 86 | + default: | |
| 87 | + $expectedFormat = 'd'; | |
| 88 | + break; | |
| 89 | + } | |
| 85 | 90 | |
| 86 | - default: | |
| 87 | - $expectedFormat = 'd'; | |
| 88 | - break; | |
| 89 | - } | |
| 91 | + return $this->getFormated($date, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ); | |
| 92 | + } | |
| 90 | 93 | |
| 91 | - return $this->getFormated($date, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ); | |
| 94 | + public function getMonth($nameType, $date = null, $currentFormat = null, $currentTZ = null, $expectedTZ = null) | |
| 95 | + { | |
| 96 | + if (is_null($date)) { | |
| 97 | + $date = $this->_currentTime; | |
| 98 | + $currentFormat = $this->_currentFormat; | |
| 99 | + $currentTZ = $this->_timezone; | |
| 92 | 100 | } |
| 93 | 101 | |
| 94 | - public function getMonth($nameType, $date = null, $currentFormat = null, $currentTZ = null, $expectedTZ = null) | |
| 95 | - { | |
| 96 | - if (is_null($date)) { | |
| 97 | - $date = $this->_currentTime; | |
| 98 | - $currentFormat = $this->_currentFormat; | |
| 99 | - $currentTZ = $this->_timezone; | |
| 100 | - } | |
| 102 | + $currentFormat = is_null($currentFormat) ? $this->_currentFormat : $currentFormat; | |
| 103 | + $currentTZ = is_null($currentTZ) ? $this->_timezone : $currentTZ; | |
| 104 | + $expectedTZ = is_null($expectedTZ) ? $this->_timezone : $expectedTZ; | |
| 101 | 105 | |
| 102 | - $currentFormat = is_null($currentFormat) ? $this->_currentFormat : $currentFormat; | |
| 103 | - $currentTZ = is_null($currentTZ) ? $this->_timezone : $currentTZ; | |
| 104 | - $expectedTZ = is_null($expectedTZ) ? $this->_timezone : $expectedTZ; | |
| 106 | + switch ($nameType) { | |
| 107 | + case 'numeric-with-leading': | |
| 108 | + $expectedFormat = 'm'; | |
| 109 | + break; | |
| 105 | 110 | |
| 106 | - switch ($nameType) { | |
| 107 | - case 'numeric-with-leading': | |
| 108 | - $expectedFormat = 'm'; | |
| 109 | - break; | |
| 111 | + case 'numeric-without-leading': | |
| 112 | + $expectedFormat = 'n'; | |
| 113 | + break; | |
| 110 | 114 | |
| 111 | - case 'numeric-without-leading': | |
| 112 | - $expectedFormat = 'n'; | |
| 113 | - break; | |
| 115 | + case 'short-name': | |
| 116 | + $expectedFormat = 'M'; | |
| 117 | + break; | |
| 114 | 118 | |
| 115 | - case 'short-name': | |
| 116 | - $expectedFormat = 'M'; | |
| 117 | - break; | |
| 119 | + case 'full-name': | |
| 120 | + $expectedFormat = 'F'; | |
| 121 | + break; | |
| 118 | 122 | |
| 119 | - case 'full-name': | |
| 120 | - $expectedFormat = 'F'; | |
| 121 | - break; | |
| 123 | + default: | |
| 124 | + $expectedFormat = 'd'; | |
| 125 | + break; | |
| 126 | + } | |
| 122 | 127 | |
| 123 | - default: | |
| 124 | - $expectedFormat = 'd'; | |
| 125 | - break; | |
| 126 | - } | |
| 128 | + return $this->getFormated($date, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ); | |
| 129 | + } | |
| 127 | 130 | |
| 128 | - return $this->getFormated($date, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ); | |
| 131 | + public function getFormated($dateString, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ) | |
| 132 | + { | |
| 133 | + if (false === $currentFormat) { | |
| 134 | + $dateObject = new DateTime($dateString, $currentTZ); | |
| 135 | + } else { | |
| 136 | + $dateObject = DateTime::createFromFormat($currentFormat, $dateString, $currentTZ); | |
| 129 | 137 | } |
| 130 | 138 | |
| 131 | - public function getFormated($dateString, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ) | |
| 132 | - { | |
| 133 | - if ($currentFormat === false) { | |
| 134 | - $dateObject = new DateTime($dateString, $currentTZ); | |
| 135 | - } else { | |
| 136 | - $dateObject = DateTime::createFromFormat($currentFormat, $dateString, $currentTZ); | |
| 137 | - } | |
| 139 | + if (!is_null($expectedTZ)) { | |
| 140 | + $dateObject->setTimezone($expectedTZ); | |
| 141 | + } | |
| 138 | 142 | |
| 139 | - if (!is_null($expectedTZ)) { | |
| 140 | - $dateObject->setTimezone($expectedTZ); | |
| 141 | - } | |
| 142 | - | |
| 143 | - if ($dateObject) { | |
| 144 | - return $dateObject->format($expectedFormat); | |
| 145 | - } | |
| 146 | - return false; | |
| 143 | + if ($dateObject) { | |
| 144 | + return $dateObject->format($expectedFormat); | |
| 147 | 145 | } |
| 146 | + return false; | |
| 147 | + } | |
| 148 | 148 | |
| 149 | - public function getUnicodeLikeFormat($type, $format = '') | |
| 150 | - { | |
| 151 | - $type = strtolower($type); | |
| 152 | - switch ($type) { | |
| 153 | - case 'date': | |
| 154 | - $format = is_null($format) ? $this->_dateFormat : $format; | |
| 155 | - break; | |
| 149 | + public function getUnicodeLikeFormat($type, $format = null) | |
| 150 | + { | |
| 151 | + $type = strtolower($type); | |
| 152 | + switch ($type) { | |
| 153 | + case 'date': | |
| 154 | + $format = is_null($format) ? $this->_dateFormat : $format; | |
| 155 | + break; | |
| 156 | 156 | |
| 157 | - case 'time': | |
| 158 | - $format = is_null($format) ? $this->_timeFormat : $format; | |
| 159 | - break; | |
| 157 | + case 'time': | |
| 158 | + $format = is_null($format) ? $this->_timeFormat : $format; | |
| 159 | + break; | |
| 160 | 160 | |
| 161 | - case 'timestamp': | |
| 162 | - $format = is_null($format) ? $this->_currentFormat : $format; | |
| 163 | - break; | |
| 161 | + case 'timestamp': | |
| 162 | + $format = is_null($format) ? $this->_currentFormat : $format; | |
| 163 | + break; | |
| 164 | 164 | |
| 165 | - default: | |
| 166 | - break; | |
| 167 | - } | |
| 165 | + default: | |
| 166 | + break; | |
| 167 | + } | |
| 168 | 168 | |
| 169 | - if (strpos($format, 'd') !== false) { | |
| 170 | - $format = str_replace('d', 'dd', $format); | |
| 171 | - } | |
| 172 | - if (strpos($format, 'j') !== false) { | |
| 173 | - $format = str_replace('j', 'd', $format); | |
| 174 | - } | |
| 175 | - if (strpos($format, 'D') !== false) { | |
| 176 | - $format = str_replace('D', 'eee', $format); | |
| 177 | - } | |
| 178 | - if (strpos($format, 'I') !== false) { | |
| 179 | - $format = str_replace('I', 'eeee', $format); | |
| 180 | - } | |
| 181 | - if (strpos($format, 'S') !== false) { | |
| 182 | - $format = str_replace('S', 'F', $format); | |
| 183 | - } | |
| 184 | - if (strpos($format, 'M') !== false) { | |
| 185 | - $format = str_replace('M', 'MMM', $format); | |
| 186 | - } | |
| 187 | - if (strpos($format, 'F') !== false) { | |
| 188 | - $format = str_replace('F', 'MMMM', $format); | |
| 189 | - } | |
| 190 | - if (strpos($format, 'm') !== false) { | |
| 191 | - $format = str_replace('m', 'MM', $format); | |
| 192 | - } | |
| 193 | - if (strpos($format, 'n') !== false) { | |
| 194 | - $format = str_replace('n', 'M', $format); | |
| 195 | - } | |
| 196 | - if (strpos($format, 'y') !== false) { | |
| 197 | - $format = str_replace('y', 'yy', $format); | |
| 198 | - } | |
| 199 | - if (strpos($format, 'Y') !== false) { | |
| 200 | - $format = str_replace('Y', 'yyyy', $format); | |
| 201 | - } | |
| 202 | - if (strpos($format, 'a') !== false) { | |
| 203 | - $format = str_replace('a', 'aaaa', $format); | |
| 204 | - } | |
| 205 | - if (strpos($format, 'A') !== false) { | |
| 206 | - $format = str_replace('A', 'aaaa', $format); | |
| 207 | - } | |
| 208 | - if (strpos($format, 'g') !== false) { | |
| 209 | - $format = str_replace('g', 'h', $format); | |
| 210 | - } | |
| 211 | - if (strpos($format, 'G') !== false) { | |
| 212 | - $format = str_replace('G', 'H', $format); | |
| 213 | - } | |
| 214 | - if (strpos($format, 'h') !== false) { | |
| 215 | - $format = str_replace('h', 'hh', $format); | |
| 216 | - } | |
| 217 | - if (strpos($format, 'H') !== false) { | |
| 218 | - $format = str_replace('H', 'HH', $format); | |
| 219 | - } | |
| 220 | - if (strpos($format, 'i') !== false) { | |
| 221 | - $format = str_replace('i', 'mm', $format); | |
| 222 | - } | |
| 223 | - if (strpos($format, 's') !== false) { | |
| 224 | - $format = str_replace('s', 'ss', $format); | |
| 225 | - } | |
| 226 | - return $format; | |
| 169 | + if (false !== strpos($format, 'd')) { | |
| 170 | + $format = str_replace('d', 'dd', $format); | |
| 227 | 171 | } |
| 172 | + if (false !== strpos($format, 'j')) { | |
| 173 | + $format = str_replace('j', 'd', $format); | |
| 174 | + } | |
| 175 | + if (false !== strpos($format, 'D')) { | |
| 176 | + $format = str_replace('D', 'eee', $format); | |
| 177 | + } | |
| 178 | + if (false !== strpos($format, 'I')) { | |
| 179 | + $format = str_replace('I', 'eeee', $format); | |
| 180 | + } | |
| 181 | + if (false !== strpos($format, 'S')) { | |
| 182 | + $format = str_replace('S', 'F', $format); | |
| 183 | + } | |
| 184 | + if (false !== strpos($format, 'M')) { | |
| 185 | + $format = str_replace('M', 'MMM', $format); | |
| 186 | + } | |
| 187 | + if (false !== strpos($format, 'F')) { | |
| 188 | + $format = str_replace('F', 'MMMM', $format); | |
| 189 | + } | |
| 190 | + if (false !== strpos($format, 'm')) { | |
| 191 | + $format = str_replace('m', 'MM', $format); | |
| 192 | + } | |
| 193 | + if (false !== strpos($format, 'n')) { | |
| 194 | + $format = str_replace('n', 'M', $format); | |
| 195 | + } | |
| 196 | + if (false !== strpos($format, 'y')) { | |
| 197 | + $format = str_replace('y', 'yy', $format); | |
| 198 | + } | |
| 199 | + if (false !== strpos($format, 'Y')) { | |
| 200 | + $format = str_replace('Y', 'yyyy', $format); | |
| 201 | + } | |
| 202 | + if (false !== strpos($format, 'a')) { | |
| 203 | + $format = str_replace('a', 'aaaa', $format); | |
| 204 | + } | |
| 205 | + if (false !== strpos($format, 'A')) { | |
| 206 | + $format = str_replace('A', 'aaaa', $format); | |
| 207 | + } | |
| 208 | + if (false !== strpos($format, 'g')) { | |
| 209 | + $format = str_replace('g', 'h', $format); | |
| 210 | + } | |
| 211 | + if (false !== strpos($format, 'G')) { | |
| 212 | + $format = str_replace('G', 'H', $format); | |
| 213 | + } | |
| 214 | + if (false !== strpos($format, 'h')) { | |
| 215 | + $format = str_replace('h', 'hh', $format); | |
| 216 | + } | |
| 217 | + if (false !== strpos($format, 'H')) { | |
| 218 | + $format = str_replace('H', 'HH', $format); | |
| 219 | + } | |
| 220 | + if (false !== strpos($format, 'i')) { | |
| 221 | + $format = str_replace('i', 'mm', $format); | |
| 222 | + } | |
| 223 | + if (false !== strpos($format, 's')) { | |
| 224 | + $format = str_replace('s', 'ss', $format); | |
| 225 | + } | |
| 226 | + return $format; | |
| 227 | + } | |
| 228 | 228 | |
| 229 | - public function getUnicodeToPhpFormat($type, $format = null) | |
| 230 | - { | |
| 231 | - $type = strtolower($type); | |
| 232 | - switch ($type) { | |
| 233 | - case 'date': | |
| 234 | - $format = is_null($format) ? $this->_dateFormat : $format; | |
| 235 | - break; | |
| 229 | + public function getUnicodeToPhpFormat($type, $format = null) | |
| 230 | + { | |
| 231 | + $type = strtolower($type); | |
| 232 | + switch ($type) { | |
| 233 | + case 'date': | |
| 234 | + $format = is_null($format) ? $this->_dateFormat : $format; | |
| 235 | + break; | |
| 236 | 236 | |
| 237 | - case 'time': | |
| 238 | - $format = is_null($format) ? $this->_timeFormat : $format; | |
| 239 | - break; | |
| 237 | + case 'time': | |
| 238 | + $format = is_null($format) ? $this->_timeFormat : $format; | |
| 239 | + break; | |
| 240 | 240 | |
| 241 | - case 'timestamp': | |
| 242 | - $format = is_null($format) ? $this->_currentFormat : $format; | |
| 243 | - break; | |
| 244 | - default: | |
| 245 | - break; | |
| 246 | - } | |
| 241 | + case 'timestamp': | |
| 242 | + $format = is_null($format) ? $this->_currentFormat : $format; | |
| 243 | + break; | |
| 244 | + default: | |
| 245 | + break; | |
| 246 | + } | |
| 247 | 247 | |
| 248 | - if (strpos($format, 'd') !== false) { | |
| 249 | - $format = str_replace('dd', 'd', $format); | |
| 250 | - } | |
| 251 | - if (strpos($format, 'E') !== false) { | |
| 252 | - $format = str_replace('E', 'D', $format); | |
| 253 | - } | |
| 254 | - if (strpos($format, 'MMMM') !== false) { | |
| 255 | - $format = str_replace('MMMM', 'F', $format); | |
| 256 | - } elseif (strpos($format, 'MMM') !== false) { | |
| 257 | - $format = str_replace('MMM', 'M', $format); | |
| 258 | - } elseif (strpos($format, 'MM') !== false) { | |
| 259 | - $format = str_replace('MM', 'm', $format); | |
| 260 | - } | |
| 261 | - if (strpos($format, 'yyyy') !== false) { | |
| 262 | - $format = str_replace('yyyy', 'Y', $format); | |
| 263 | - } elseif (strpos($format, 'yy') !== false) { | |
| 264 | - $format = str_replace('yy', 'y', $format); | |
| 265 | - } | |
| 266 | - return $format; | |
| 248 | + if (false !== strpos($format, 'd')) { | |
| 249 | + $format = str_replace('dd', 'd', $format); | |
| 267 | 250 | } |
| 251 | + if (false !== strpos($format, 'E')) { | |
| 252 | + $format = str_replace('E', 'D', $format); | |
| 253 | + } | |
| 254 | + if (false !== strpos($format, 'MMMM')) { | |
| 255 | + $format = str_replace('MMMM', 'F', $format); | |
| 256 | + } elseif (false !== strpos($format, 'MMM')) { | |
| 257 | + $format = str_replace('MMM', 'M', $format); | |
| 258 | + } elseif (false !== strpos($format, 'MM')) { | |
| 259 | + $format = str_replace('MM', 'm', $format); | |
| 260 | + } | |
| 261 | + if (false !== strpos($format, 'yyyy')) { | |
| 262 | + $format = str_replace('yyyy', 'Y', $format); | |
| 263 | + } elseif (false !== strpos($format, 'yy')) { | |
| 264 | + $format = str_replace('yy', 'y', $format); | |
| 265 | + } | |
| 266 | + return $format; | |
| 267 | + } | |
| 268 | 268 | |
| 269 | - public static function wp_timezone_string() | |
| 270 | - { | |
| 271 | - if (\function_exists('wp_timezone_string')) { | |
| 272 | - return wp_timezone_string(); | |
| 273 | - } | |
| 269 | + public static function wp_timezone_string() | |
| 270 | + { | |
| 271 | + if (\function_exists('wp_timezone_string')) { | |
| 272 | + return wp_timezone_string(); | |
| 273 | + } | |
| 274 | 274 | |
| 275 | - $timezone_string = get_option('timezone_string'); | |
| 275 | + $timezone_string = get_option('timezone_string'); | |
| 276 | 276 | |
| 277 | - if ($timezone_string) { | |
| 278 | - return $timezone_string; | |
| 279 | - } | |
| 277 | + if ($timezone_string) { | |
| 278 | + return $timezone_string; | |
| 279 | + } | |
| 280 | 280 | |
| 281 | - $offset = (float) get_option('gmt_offset'); | |
| 282 | - $hours = (int) $offset; | |
| 283 | - $minutes = ($offset - $hours); | |
| 281 | + $offset = (float) get_option('gmt_offset'); | |
| 282 | + $hours = (int) $offset; | |
| 283 | + $minutes = ($offset - $hours); | |
| 284 | 284 | |
| 285 | - $sign = ($offset < 0) ? '-' : '+'; | |
| 286 | - $abs_hour = abs($hours); | |
| 287 | - $abs_mins = abs($minutes * 60); | |
| 288 | - $tz_offset = sprintf('%s%02d:%02d', $sign, $abs_hour, $abs_mins); | |
| 285 | + $sign = ($offset < 0) ? '-' : '+'; | |
| 286 | + $abs_hour = abs($hours); | |
| 287 | + $abs_mins = abs($minutes * 60); | |
| 288 | + $tz_offset = sprintf('%s%02d:%02d', $sign, $abs_hour, $abs_mins); | |
| 289 | 289 | |
| 290 | - return $tz_offset; | |
| 291 | - } | |
| 290 | + return $tz_offset; | |
| 291 | + } | |
| 292 | 292 | |
| 293 | - public static function wp_timezone() | |
| 294 | - { | |
| 295 | - if (\function_exists('wp_timezone')) { | |
| 296 | - return wp_timezone(); | |
| 297 | - } | |
| 298 | - return new DateTimeZone(self::wp_timezone_string()); | |
| 293 | + public static function wp_timezone() | |
| 294 | + { | |
| 295 | + if (\function_exists('wp_timezone')) { | |
| 296 | + return wp_timezone(); | |
| 299 | 297 | } |
| 298 | + return new DateTimeZone(self::wp_timezone_string()); | |
| 299 | + } | |
| 300 | 300 | } |