Horde_Date::getTimezoneAlias PHP Method

getTimezoneAlias() public static method

We currently support Windows and Lotus timezone names, and timezone abbreviations.
public static getTimezoneAlias ( string $timezone ) : string
$timezone string Some timezone alias.
return string The Olson timezone name, or the original value, if no alias found.
    public static function getTimezoneAlias($timezone)
    {
        if (empty(self::$_timezoneIdentifiers)) {
            self::$_timezoneIdentifiers = array_flip(DateTimeZone::listIdentifiers());
        }
        if (isset(self::$_timezoneIdentifiers[$timezone])) {
            return $timezone;
        }
        /* Workaround for standard cases of bug #11688 */
        if (isset(self::$_timezoneAliases[$timezone])) {
            $timezone = self::$_timezoneAliases[$timezone];
        }
        if (empty(self::$_timezoneAbbreviations)) {
            self::$_timezoneAbbreviations = DateTimeZone::listAbbreviations();
        }
        $lower = Horde_String::lower($timezone);
        if (isset(self::$_timezoneAbbreviations[$lower])) {
            $timezone = reset(self::$_timezoneAbbreviations[$lower]);
            $timezone = $timezone['timezone_id'];
        }
        return $timezone;
    }

Usage Example

Exemplo n.º 1
0
 /**
  * Attempt to guess the timezone identifier from the $offsets array.
  *
  * Since it's impossible to know exactly which olson timezone name a
  * specific set of offsets represent (multiple timezone names may be
  * described by the same offsets for any given year) we allow passing an
  * expected timezone. If this matches one of the timezones that matches the
  * offsets, we return that. Otherwise, we attempt to get the full timezone
  * name from Horde_Date and if that fails, return the abbreviated timezone
  * name of the first timezone that matches the provided offsets.
  *
  * @param array|string $offsets     The timezone to check. Either an array
  *                                  of offsets or an activesynz tz blob.
  * @param string $expectedTimezone  The expected timezone. If not empty, and
  *                                  present in the results, will return.
  *
  * @return string  The timezone identifier.
  */
 public function getTimezone($offsets, $expectedTimezone = null)
 {
     $timezones = $this->getListOfTimezones($offsets, $expectedTimezone);
     if (isset($timezones[$expectedTimezone])) {
         return $expectedTimezone;
     } else {
         return Horde_Date::getTimezoneAlias(current($timezones));
     }
 }
All Usage Examples Of Horde_Date::getTimezoneAlias