ActionScheduler_TimezoneHelper::get_local_timezone
Устарела с версии 2.1.0. Больше не поддерживается и может быть удалена. Рекомендуется заменить эту функцию на аналог.
Get local timezone.
Метод класса: ActionScheduler_TimezoneHelper{}
Хуков нет.
Возвращает
null. Ничего (null).
Использование
$result = ActionScheduler_TimezoneHelper::get_local_timezone( $reset );
- $reset(true|false)
- Toggle to discard stored value.
По умолчанию:false
Список изменений
| Устарела с | 2.1.0 |
Код ActionScheduler_TimezoneHelper::get_local_timezone() ActionScheduler TimezoneHelper::get local timezone WC 10.9.4
public static function get_local_timezone( $reset = false ) {
_deprecated_function( __FUNCTION__, '2.1.0', 'ActionScheduler_TimezoneHelper::set_local_timezone()' );
if ( $reset ) {
self::$local_timezone = null;
}
if ( ! isset( self::$local_timezone ) ) {
$tzstring = get_option( 'timezone_string' );
if ( empty( $tzstring ) ) {
$gmt_offset = absint( get_option( 'gmt_offset' ) );
if ( 0 === $gmt_offset ) {
$tzstring = 'UTC';
} else {
$gmt_offset *= HOUR_IN_SECONDS;
$tzstring = timezone_name_from_abbr( '', $gmt_offset, 1 );
// If there's no timezone string, try again with no DST.
if ( false === $tzstring ) {
$tzstring = timezone_name_from_abbr( '', $gmt_offset, 0 );
}
// Try mapping to the first abbreviation we can find.
if ( false === $tzstring ) {
$is_dst = date( 'I' ); // phpcs:ignore WordPress.DateTime.RestrictedFunctions.date_date -- we are actually interested in the runtime timezone.
foreach ( timezone_abbreviations_list() as $abbr ) {
foreach ( $abbr as $city ) {
if ( $city['dst'] === $is_dst && $city['offset'] === $gmt_offset ) {
// If there's no valid timezone ID, keep looking.
if ( is_null( $city['timezone_id'] ) ) {
continue;
}
$tzstring = $city['timezone_id'];
break 2;
}
}
}
}
// If we still have no valid string, then fall back to UTC.
if ( false === $tzstring ) {
$tzstring = 'UTC';
}
}
}
self::$local_timezone = new DateTimeZone( $tzstring );
}
return self::$local_timezone;
}