← All changes
|
vendor/woocommerce/action-scheduler/classes/abstracts/ActionScheduler_TimezoneHelper.php
+17
-13
1.5.3
→
trunk
View file →
| @@ -4,10 +4,14 @@ | ||
| 4 | 4 | * Class ActionScheduler_TimezoneHelper |
| 5 | 5 | */ |
| 6 | 6 | abstract class ActionScheduler_TimezoneHelper { |
| 7 | 7 | |
| 8 | - /** @var null|DateTimeZone */ | |
| 9 | - private static $local_timezone = NULL; | |
| 8 | + /** | |
| 9 | + * DateTimeZone object. | |
| 10 | + * | |
| 11 | + * @var null|DateTimeZone | |
| 12 | + */ | |
| 13 | + private static $local_timezone = null; | |
| 10 | 14 | |
| 11 | 15 | /** |
| 12 | 16 | * Set a DateTime's timezone to the WordPress site's timezone, or a UTC offset |
| 13 | 17 | * if no timezone string is available. |
| @@ -104,23 +108,23 @@ | ||
| 104 | 108 | * |
| 105 | 109 | * @param bool $reset Toggle to discard stored value. |
| 106 | 110 | * @deprecated 2.1.0 |
| 107 | 111 | */ |
| 108 | - public static function get_local_timezone( $reset = FALSE ) { | |
| 112 | + public static function get_local_timezone( $reset = false ) { | |
| 109 | 113 | _deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' ); |
| 110 | 114 | if ( $reset ) { |
| 111 | - self::$local_timezone = NULL; | |
| 115 | + self::$local_timezone = null; | |
| 112 | 116 | } |
| 113 | - if ( !isset(self::$local_timezone) ) { | |
| 114 | - $tzstring = get_option('timezone_string'); | |
| 117 | + if ( ! isset( self::$local_timezone ) ) { | |
| 118 | + $tzstring = get_option( 'timezone_string' ); | |
| 115 | 119 | |
| 116 | - if ( empty($tzstring) ) { | |
| 117 | - $gmt_offset = get_option('gmt_offset'); | |
| 118 | - if ( $gmt_offset == 0 ) { | |
| 120 | + if ( empty( $tzstring ) ) { | |
| 121 | + $gmt_offset = absint( get_option( 'gmt_offset' ) ); | |
| 122 | + if ( 0 === $gmt_offset ) { | |
| 119 | 123 | $tzstring = 'UTC'; |
| 120 | 124 | } else { |
| 121 | 125 | $gmt_offset *= HOUR_IN_SECONDS; |
| 122 | - $tzstring = timezone_name_from_abbr( '', $gmt_offset, 1 ); | |
| 126 | + $tzstring = timezone_name_from_abbr( '', $gmt_offset, 1 ); | |
| 123 | 127 | |
| 124 | 128 | // If there's no timezone string, try again with no DST. |
| 125 | 129 | if ( false === $tzstring ) { |
| 126 | 130 | $tzstring = timezone_name_from_abbr( '', $gmt_offset, 0 ); |
| @@ -130,11 +134,11 @@ | ||
| 130 | 134 | if ( false === $tzstring ) { |
| 131 | 135 | $is_dst = date( 'I' ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- we are actually interested in the runtime timezone. |
| 132 | 136 | foreach ( timezone_abbreviations_list() as $abbr ) { |
| 133 | 137 | foreach ( $abbr as $city ) { |
| 134 | - if ( $city['dst'] == $is_dst && $city['offset'] == $gmt_offset ) { | |
| 138 | + if ( $city['dst'] === $is_dst && $city['offset'] === $gmt_offset ) { | |
| 135 | 139 | // If there's no valid timezone ID, keep looking. |
| 136 | - if ( null === $city['timezone_id'] ) { | |
| 140 | + if ( is_null( $city['timezone_id'] ) ) { | |
| 137 | 141 | continue; |
| 138 | 142 | } |
| 139 | 143 | |
| 140 | 144 | $tzstring = $city['timezone_id']; |
| @@ -150,9 +154,9 @@ | ||
| 150 | 154 | } |
| 151 | 155 | } |
| 152 | 156 | } |
| 153 | 157 | |
| 154 | - self::$local_timezone = new DateTimeZone($tzstring); | |
| 158 | + self::$local_timezone = new DateTimeZone( $tzstring ); | |
| 155 | 159 | } |
| 156 | 160 | return self::$local_timezone; |
| 157 | 161 | } |
| 158 | 162 | } |