iso8601_timezone_to_offset

The timeline below displays how wordpress function iso8601_timezone_to_offset has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Given an ISO 8601 timezone, returns its UTC offset in seconds.
 *
 * @since 1.5.0
 *
 * @param string $timezone Either 'Z' for 0 offset or '±hhmm'.
 * @return int|float The offset in seconds.
 */
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;
}

WordPress Version: 5.6

/**
 * Given an ISO 8601 timezone, returns its UTC offset in seconds.
 *
 * @since 1.5.0
 *
 * @param string $timezone Either 'Z' for 0 offset or '±hhmm'.
 * @return int|float The offset in seconds.
 */
function iso8601_timezone_to_offset($timezone)
{
    // $timezone is either 'Z' or '[+|-]hhmm'.
    if ('Z' === $timezone) {
        $offset = 0;
    } else {
        $sign = ('+' === substr($timezone, 0, 1)) ? 1 : -1;
        $hours = (int) substr($timezone, 1, 2);
        $minutes = (int) substr($timezone, 3, 4) / 60;
        $offset = $sign * HOUR_IN_SECONDS * ($hours + $minutes);
    }
    return $offset;
}

WordPress Version: 5.5

/**
 * Given an ISO 8601 timezone, returns its UTC offset in seconds.
 *
 * @since 1.5.0
 *
 * @param string $timezone Either 'Z' for 0 offset or '±hhmm'.
 * @return int|float The offset in seconds.
 */
function iso8601_timezone_to_offset($timezone)
{
    // $timezone is either 'Z' or '[+|-]hhmm'.
    if ('Z' === $timezone) {
        $offset = 0;
    } else {
        $sign = ('+' === substr($timezone, 0, 1)) ? 1 : -1;
        $hours = intval(substr($timezone, 1, 2));
        $minutes = intval(substr($timezone, 3, 4)) / 60;
        $offset = $sign * HOUR_IN_SECONDS * ($hours + $minutes);
    }
    return $offset;
}

WordPress Version: 5.4

/**
 * Computes an offset in seconds from an iso8601 timezone.
 *
 * @since 1.5.0
 *
 * @param string $timezone Either 'Z' for 0 offset or '±hhmm'.
 * @return int|float The offset in seconds.
 */
function iso8601_timezone_to_offset($timezone)
{
    // $timezone is either 'Z' or '[+|-]hhmm'.
    if ('Z' === $timezone) {
        $offset = 0;
    } else {
        $sign = (substr($timezone, 0, 1) == '+') ? 1 : -1;
        $hours = intval(substr($timezone, 1, 2));
        $minutes = intval(substr($timezone, 3, 4)) / 60;
        $offset = $sign * HOUR_IN_SECONDS * ($hours + $minutes);
    }
    return $offset;
}

WordPress Version: 3.7

/**
 * Computes an offset in seconds from an iso8601 timezone.
 *
 * @since 1.5.0
 *
 * @param string $timezone Either 'Z' for 0 offset or '±hhmm'.
 * @return int|float The offset in seconds.
 */
function iso8601_timezone_to_offset($timezone)
{
    // $timezone is either 'Z' or '[+|-]hhmm'
    if ($timezone == 'Z') {
        $offset = 0;
    } else {
        $sign = (substr($timezone, 0, 1) == '+') ? 1 : -1;
        $hours = intval(substr($timezone, 1, 2));
        $minutes = intval(substr($timezone, 3, 4)) / 60;
        $offset = $sign * HOUR_IN_SECONDS * ($hours + $minutes);
    }
    return $offset;
}