ActionScheduler_TimezoneHelper::get_local_timezonepublic staticWC 1.0

Deprecated since 2.1.0. It is no longer supported and may be removed in future releases. It is recommended to replace this function with the same one.

Get local timezone.

Method of the class: ActionScheduler_TimezoneHelper{}

No Hooks.

Returns

null. Nothing (null).

Usage

$result = ActionScheduler_TimezoneHelper::get_local_timezone( $reset );
$reset(true|false)
Toggle to discard stored value.
Default: false

Changelog

Deprecated since 2.1.0

ActionScheduler_TimezoneHelper::get_local_timezone() code WC 9.9.5

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;
}