Horde_Mapi_Timezone::getTimezone PHP Method

getTimezone() public method

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.
public getTimezone ( array | string $offsets, string $expectedTimezone = null ) : string
$offsets array | string The timezone to check. Either an array of offsets or an activesynz tz blob.
$expectedTimezone string 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));
        }
    }

Usage Example

示例#1
0
 /**
  * Test guessing a timezone identifier from an ActiveSync timezone
  * structure.
  */
 public function testGuessTimezoneFromOffsets()
 {
     $timezones = new Horde_Mapi_Timezone();
     // Test general functionality, with expected timezone.
     foreach ($this->_packed as $tz => $blob) {
         $guessed = $timezones->getTimezone($blob, $tz);
         $this->assertEquals($tz, $guessed);
     }
     // Test without a known timezone
     $guessed = $timezones->getTimezone($this->_packed['America/New_York']);
     $this->assertEquals('America/New_York', $guessed);
     $guessed = $timezones->getTimezone($this->_packed['Europe/Berlin']);
     $this->assertEquals('Europe/Berlin', $guessed);
 }
All Usage Examples Of Horde_Mapi_Timezone::getTimezone