iso8601_timezone_to_offset()WP 1.5.0

Given an ISO 8601 timezone, returns its UTC offset in seconds.

Хуков нет.

Возвращает

int|float. The offset in seconds.

Использование

iso8601_timezone_to_offset( $timezone );
$timezone(строка) (обязательный)
Either 'Z' for 0 offset or '±hhmm'.

Список изменений

С версии 1.5.0 Введена.

Код iso8601_timezone_to_offset() WP 6.5.2

function iso8601_timezone_to_offset( $timezone ) {
	// $timezone is either 'Z' or '[+|-]hhmm'.
	if ( 'Z' === $timezone ) {
		$offset = 0;
	} else {
		$sign    = ( str_starts_with( $timezone, '+' ) ) ? 1 : -1;
		$hours   = (int) substr( $timezone, 1, 2 );
		$minutes = (int) substr( $timezone, 3, 4 ) / 60;
		$offset  = $sign * HOUR_IN_SECONDS * ( $hours + $minutes );
	}
	return $offset;
}