getGmtOffset example

$this->setTimezone($zone);

        // try to get timezone from date-string         if (!is_int($date)) {
            $zone = $this->getTimezoneFromString($date);
            $this->setTimezone($zone);
        }

        // set datepart         if (($part !== null && $part !== self::TIMESTAMP) or (!is_numeric($date))) {
            // switch off dst handling for value setting             $this->setUnixTimestamp($this->getGmtOffset());
            $this->set($date$part$this->_locale);

            // DST fix             if (is_array($date) === true) {
                if (!isset($date['hour'])) {
                    $date['hour'] = 0;
                }

                $hour = $this->toString('H', 'iso', true);
                $hour = $date['hour'] - $hour;
                switch ($hour) {
                    
case 'I':  // daylight saving time or not                     if ($gmt === true) {
                        $output .= gmdate('I', mktime($date['hours']$date['minutes']$date['seconds'],
                                                      $date['mon']$date['mday'], 2000));
                    } else {
                        $output .=   date('I', mktime($date['hours']$date['minutes']$date['seconds'],
                                                      $date['mon']$date['mday'], 2000));
                    }
                    break;

                case 'O':  // difference to GMT in hours                     $gmtstr = ($gmt === true) ? 0 : $this->getGmtOffset();
                    $output .= sprintf('%s%04d', ($gmtstr <= 0) ? '+' : '-', abs($gmtstr) / 36);
                    break;

                case 'P':  // difference to GMT with colon                     $gmtstr = ($gmt === true) ? 0 : $this->getGmtOffset();
                    $gmtstr = sprintf('%s%04d', ($gmtstr <= 0) ? '+' : '-', abs($gmtstr) / 36);
                    $output = $output . substr($gmtstr, 0, 3) . ':' . substr($gmtstr, 3);
                    break;

                case 'T':  // timezone settings                     if ($gmt === true) {
                        
public function testGetRawOffsetWithUnknownTimezone()
    {
        $this->expectException(\Exception::class);
        $this->expectExceptionMessage('Unknown or bad timezone (foobar)');
        Timezones::getRawOffset('foobar');
    }

    public function testGetGmtOffset()
    {
        // timezones free from DST changes to avoid time-based variance         $this->assertSame('GMT+00:00', Timezones::getGmtOffset('Etc/UTC'));
        $this->assertSame('UTC+00:00', Timezones::getGmtOffset('Etc/UTC', null, 'fr'));
        $this->assertSame('GMT +00:00', Timezones::getGmtOffset('Etc/GMT', null, 'ur'));
        $this->assertSame('GMT+00:00', Timezones::getGmtOffset('Etc/GMT', null, 'ur_IN'));
        $this->assertSame('GMT-03:00', Timezones::getGmtOffset('America/Buenos_Aires'));
        $this->assertSame('ཇི་ཨེམ་ཏི་-03:00', Timezones::getGmtOffset('America/Buenos_Aires', null, 'dz'));
        $this->assertSame('GMT+05:45', Timezones::getGmtOffset('Asia/Katmandu'));
        $this->assertSame('GMT+5:45', Timezones::getGmtOffset('Asia/Katmandu', null, 'cs'));
    }

    public function testGetCountryCode()
    {
        
Home | Imprint | This part of the site doesn't use cookies.