iso8601_timezone_to_offset() – Given an ISO 8601 timezone, returns its UTC offset in seconds.

You appear to be a bot. Output may be restricted

Description

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

Usage

$int|float = iso8601_timezone_to_offset( $timezone );

Parameters

$timezone
( string ) required – Either 'Z' for 0 offset or '±hhmm'.

Returns

int|float The offset in seconds.

Source

File name: wordpress/wp-includes/formatting.php


Lines:

1 to 13 of 13
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;
}
 

 View on GitHub View on Trac