| @@ -4,9 +4,10 @@ | ||
| 4 | 4 | |
| 5 | 5 | use DateTime; |
| 6 | 6 | use DateTimeZone; |
| 7 | 7 | |
| 8 | -final class DateTimeHelper { | |
| 8 | +final class DateTimeHelper | |
| 9 | +{ | |
| 9 | 10 | private $_dateFormat; |
| 10 | 11 | private $_timeFormat; |
| 11 | 12 | private $_timezone; |
| 12 | 13 | private $_currentTime; |
| @@ -11,9 +12,10 @@ | ||
| 11 | 12 | private $_timezone; |
| 12 | 13 | private $_currentTime; |
| 13 | 14 | private $_currentFormat; |
| 14 | 15 | |
| 15 | - public function __construct() { | |
| 16 | + public function __construct() | |
| 17 | + { | |
| 16 | 18 | $this->_dateFormat = get_option('date_format'); |
| 17 | 19 | $this->_timeFormat = get_option('time_format'); |
| 18 | 20 | $this->_timezone = self::wp_timezone(); |
| 19 | 21 | $this->_currentTime = current_time('mysql'); |
| @@ -19,9 +21,10 @@ | ||
| 19 | 21 | $this->_currentTime = current_time('mysql'); |
| 20 | 22 | $this->_currentFormat = 'Y-m-d H:i:s'; |
| 21 | 23 | } |
| 22 | 24 | |
| 23 | - public function getDate($date = null, $currentFormat = null, $currentTZ = null, $expectedFormat = null, $expectedTZ = null) { | |
| 25 | + public function getDate($date = null, $currentFormat = null, $currentTZ = null, $expectedFormat = null, $expectedTZ = null) | |
| 26 | + { | |
| 24 | 27 | if (is_null($date)) { |
| 25 | 28 | $date = $this->_currentTime; |
| 26 | 29 | $currentFormat = $this->_currentFormat; |
| 27 | 30 | $currentTZ = $this->_timezone; |
| @@ -34,9 +37,10 @@ | ||
| 34 | 37 | |
| 35 | 38 | return $this->getFormated($date, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ); |
| 36 | 39 | } |
| 37 | 40 | |
| 38 | - public function getTime($date = null, $currentFormat = null, $currentTZ = null, $expectedFormat = null, $expectedTZ = null) { | |
| 41 | + public function getTime($date = null, $currentFormat = null, $currentTZ = null, $expectedFormat = null, $expectedTZ = null) | |
| 42 | + { | |
| 39 | 43 | if (is_null($date)) { |
| 40 | 44 | $date = $this->_currentTime; |
| 41 | 45 | $currentFormat = $this->_currentFormat; |
| 42 | 46 | $currentTZ = $this->_timezone; |
| @@ -49,9 +53,10 @@ | ||
| 49 | 53 | |
| 50 | 54 | return $this->getFormated($date, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ); |
| 51 | 55 | } |
| 52 | 56 | |
| 53 | - public function getDay($nameType, $date = null, $currentFormat = null, $currentTZ = null, $expectedTZ = null) { | |
| 57 | + public function getDay($nameType, $date = null, $currentFormat = null, $currentTZ = null, $expectedTZ = null) | |
| 58 | + { | |
| 54 | 59 | if (is_null($date)) { |
| 55 | 60 | $date = $this->_currentTime; |
| 56 | 61 | $currentFormat = $this->_currentFormat; |
| 57 | 62 | $currentTZ = $this->_timezone; |
| @@ -85,9 +90,10 @@ | ||
| 85 | 90 | |
| 86 | 91 | return $this->getFormated($date, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ); |
| 87 | 92 | } |
| 88 | 93 | |
| 89 | - public function getMonth($nameType, $date = null, $currentFormat = null, $currentTZ = null, $expectedTZ = null) { | |
| 94 | + public function getMonth($nameType, $date = null, $currentFormat = null, $currentTZ = null, $expectedTZ = null) | |
| 95 | + { | |
| 90 | 96 | if (is_null($date)) { |
| 91 | 97 | $date = $this->_currentTime; |
| 92 | 98 | $currentFormat = $this->_currentFormat; |
| 93 | 99 | $currentTZ = $this->_timezone; |
| @@ -121,9 +127,10 @@ | ||
| 121 | 127 | |
| 122 | 128 | return $this->getFormated($date, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ); |
| 123 | 129 | } |
| 124 | 130 | |
| 125 | - public function getFormated($dateString, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ) { | |
| 131 | + public function getFormated($dateString, $currentFormat, $currentTZ, $expectedFormat, $expectedTZ) | |
| 132 | + { | |
| 126 | 133 | if (false === $currentFormat) { |
| 127 | 134 | $dateObject = new DateTime($dateString, $currentTZ); |
| 128 | 135 | } else { |
| 129 | 136 | $dateObject = DateTime::createFromFormat($currentFormat, $dateString, $currentTZ); |
| @@ -138,9 +145,10 @@ | ||
| 138 | 145 | } |
| 139 | 146 | return false; |
| 140 | 147 | } |
| 141 | 148 | |
| 142 | - public function getUnicodeLikeFormat($type, $format = null) { | |
| 149 | + public function getUnicodeLikeFormat($type, $format = null) | |
| 150 | + { | |
| 143 | 151 | $type = strtolower($type); |
| 144 | 152 | switch ($type) { |
| 145 | 153 | case 'date': |
| 146 | 154 | $format = is_null($format) ? $this->_dateFormat : $format; |
| @@ -217,9 +225,10 @@ | ||
| 217 | 225 | } |
| 218 | 226 | return $format; |
| 219 | 227 | } |
| 220 | 228 | |
| 221 | - public function getUnicodeToPhpFormat($type, $format = null) { | |
| 229 | + public function getUnicodeToPhpFormat($type, $format = null) | |
| 230 | + { | |
| 222 | 231 | $type = strtolower($type); |
| 223 | 232 | switch ($type) { |
| 224 | 233 | case 'date': |
| 225 | 234 | $format = is_null($format) ? $this->_dateFormat : $format; |
| @@ -256,9 +265,10 @@ | ||
| 256 | 265 | } |
| 257 | 266 | return $format; |
| 258 | 267 | } |
| 259 | 268 | |
| 260 | - public static function wp_timezone_string() { | |
| 269 | + public static function wp_timezone_string() | |
| 270 | + { | |
| 261 | 271 | if (\function_exists('wp_timezone_string')) { |
| 262 | 272 | return wp_timezone_string(); |
| 263 | 273 | } |
| 264 | 274 | |
| @@ -279,9 +289,10 @@ | ||
| 279 | 289 | |
| 280 | 290 | return $tz_offset; |
| 281 | 291 | } |
| 282 | 292 | |
| 283 | - public static function wp_timezone() { | |
| 293 | + public static function wp_timezone() | |
| 294 | + { | |
| 284 | 295 | if (\function_exists('wp_timezone')) { |
| 285 | 296 | return wp_timezone(); |
| 286 | 297 | } |
| 287 | 298 | return new DateTimeZone(self::wp_timezone_string()); |