function do_test(IntlTimeZone $tz, $proc = false)
{
    var_dump($tz->getID(), $tz->getRawOffset());
    if (!$proc) {
        $dtz = $tz->toDateTimeZone();
    } else {
        $dtz = intltz_to_date_time_zone($tz);
    }
    var_dump($dtz->getName(), $dtz->getOffset(new DateTime('2012-01-01 00:00:00')));
}
Пример #2
0
 /**
  * @return mixed[]
  */
 public function formatProvider()
 {
     $icuUpToDate = version_compare(Intl::getIcuVersion(), '50.0', '>=');
     $icuComma = $icuUpToDate ? ',' : '';
     $icuAt = $icuUpToDate ? ' at' : '';
     $datetime = new \DateTime('2015-01-01 00:00:00', new \DateTimeZone('Europe/Paris'));
     return ['default' => [$datetime, [], 'Jan 1, 2015' . $icuComma . ' 12:00:00 AM'], 'date_format_none' => [$datetime, ['date_format' => \IntlDateFormatter::NONE], '12:00:00 AM'], 'date_format_shot' => [$datetime, ['date_format' => \IntlDateFormatter::SHORT], '1/1/15' . $icuComma . ' 12:00:00 AM'], 'date_format_medium' => [$datetime, ['date_format' => \IntlDateFormatter::MEDIUM], 'Jan 1, 2015' . $icuComma . ' 12:00:00 AM'], 'date_format_long' => [$datetime, ['date_format' => \IntlDateFormatter::LONG], 'January 1, 2015' . $icuAt . ' 12:00:00 AM'], 'date_format_full' => [$datetime, ['date_format' => \IntlDateFormatter::FULL], 'Thursday, January 1, 2015' . $icuAt . ' 12:00:00 AM'], 'time_format_none' => [$datetime, ['time_format' => \IntlDateFormatter::NONE], 'Jan 1, 2015'], 'time_format_shot' => [$datetime, ['time_format' => \IntlDateFormatter::SHORT], 'Jan 1, 2015' . $icuComma . ' 12:00 AM'], 'time_format_medium' => [$datetime, ['time_format' => \IntlDateFormatter::MEDIUM], 'Jan 1, 2015' . $icuComma . ' 12:00:00 AM'], 'time_format_long' => [$datetime, ['time_format' => \IntlDateFormatter::LONG], 'Jan 1, 2015' . $icuComma . ' 12:00:00 AM GMT+' . ($icuUpToDate ? '1' : '01:00')], 'time_format_full' => [$datetime, ['time_format' => \IntlDateFormatter::FULL], 'Jan 1, 2015' . $icuComma . ' 12:00:00 AM Central European' . ($icuUpToDate ? ' Standard' : '') . ' Time'], 'timezone' => [$datetime, ['timezone' => 'UTC'], 'Dec 31, 2014' . $icuComma . ' 11:00:00 PM'], 'int_timezone' => [$datetime, ['timezone' => \IntlTimeZone::createTimeZone('UTC')], 'Dec 31, 2014' . $icuComma . ' 11:00:00 PM'], 'date_timezone' => [$datetime, ['timezone' => new \DateTimeZone('UTC')], 'Dec 31, 2014' . $icuComma . ' 11:00:00 PM'], 'gregorian_calendar' => [$datetime, ['calendar' => \IntlDateFormatter::GREGORIAN], 'Jan 1, 2015' . $icuComma . ' 12:00:00 AM'], 'intl_calendar' => [$datetime, ['calendar' => \IntlCalendar::createInstance('UTC')], 'Jan 1, 2015' . $icuComma . ' 12:00:00 AM'], 'pattern' => [$datetime, ['pattern' => 'YYYY/MM/dd'], '2015/01/01']];
 }
Пример #3
0
 /**
  * Retrieve list of timezones
  *
  * @return array
  */
 public function getTimezoneList()
 {
     $zones = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL);
     $list = [];
     foreach ($zones as $code) {
         $list[$code] = \IntlTimeZone::createTimeZone($code)->getDisplayName(false, \IntlTimeZone::DISPLAY_LONG, ResolverInterface::DEFAULT_LOCALE) . ' (' . $code . ')';
     }
     asort($list);
     return $list;
 }
<?php

ini_set("intl.error_level", E_WARNING);
var_dump(IntlTimeZone::createEnumeration(array()));
var_dump(IntlTimeZone::createEnumeration(1, 2));
Пример #5
0
 public function testConfigureOptionsWithIntlTimezone()
 {
     $this->type->configureOptions($resolver = new OptionsResolver());
     $this->assertSame(['path' => $path = 'path_value', 'calendar' => null, 'date_format' => \IntlDateFormatter::MEDIUM, 'lenient' => false, 'pattern' => null, 'timezone' => $timezone = \IntlTimeZone::createTimeZone('Europe/Paris'), 'time_format' => \IntlDateFormatter::MEDIUM], $resolver->resolve(['path' => $path, 'timezone' => $timezone]));
 }
 public function testFormatWithIntlTimeZone()
 {
     if (!extension_loaded('intl')) {
         $this->markTestSkipped('Extension intl is required.');
     }
     $formatter = $this->getDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, \IntlTimeZone::createTimeZone('GMT+03:00'), IntlDateFormatter::GREGORIAN, 'zzzz');
     $this->assertEquals('GMT+03:00', $formatter->format(0));
 }
<?php

ini_set("intl.error_level", E_WARNING);
$tz = IntlTimeZone::createTimeZone('Europe/Lisbon');
var_dump($tz->getErrorMessage(array()));
var_dump(intltz_get_error_message(null));
<?php

ini_set("intl.error_level", E_WARNING);
$tz = IntlTimeZone::createTimeZone('GMT+01:00');
print_r($tz);
$tz = intltz_create_time_zone('GMT+01:00');
print_r($tz);
?>
==DONE==
<?php

ini_set("intl.error_level", E_WARNING);
print_R(IntlTimeZone::getEquivalentID('Europe/Lisbon', "1"));
echo "\n";
print_R(intltz_get_equivalent_id('Europe/Lisbon', 1));
echo "\n";
?>
==DONE==
Пример #10
0
 /**
  * @return DateTimeZone|null
  */
 public function getTimeZone()
 {
     $pointCurrent = $this->getGeoPoint();
     if (null === $pointCurrent) {
         return null;
     }
     $timezoneNameList = \Functional\reject(DateTimeZone::listIdentifiers(), function ($timeZoneName) {
         return null === IntlTimeZone::fromDateTimeZone(new DateTimeZone($timeZoneName));
     });
     $distanceList = Functional\map($timezoneNameList, function ($timezoneName) use($pointCurrent) {
         $timezoneLocation = (new DateTimeZone($timezoneName))->getLocation();
         $pointTimeZone = new CM_Geo_Point($timezoneLocation['latitude'], $timezoneLocation['longitude']);
         return ['timezoneName' => $timezoneName, 'distance' => $pointCurrent->calculateDistanceTo($pointTimeZone)];
     });
     $closestDistance = Functional\reduce_left($distanceList, function (array $current, $index, $collection, array $minimal) {
         return $current['distance'] < $minimal['distance'] ? $current : $minimal;
     }, $distanceList[0]);
     return new DateTimeZone($closestDistance['timezoneName']);
 }
Пример #11
0
 /**
  * @inheritdoc
  */
 public function getOptionTimezones()
 {
     $options = [];
     $locale = $this->localeResolver->getLocale();
     $zones = \DateTimeZone::listIdentifiers(\DateTimeZone::ALL) ?: [];
     foreach ($zones as $code) {
         $options[] = ['label' => \IntlTimeZone::createTimeZone($code)->getDisplayName(false, \IntlTimeZone::DISPLAY_LONG, $locale) . ' (' . $code . ')', 'value' => $code];
     }
     return $this->_sortOptionArray($options);
 }
Пример #12
0
<?php

ini_set("intl.error_level", E_WARNING);
var_dump(IntlTimeZone::createDefault(4));
Пример #13
0
<?php

ini_set("intl.error_level", E_WARNING);
$c = new IntlGregorianCalendar(NULL, 'pt_PT');
$gmt = IntlTimeZone::getGMT();
function eh($errno, $errstr)
{
    echo "error: {$errno}, {$errstr}\n";
}
set_error_handler('eh');
var_dump($c->setTimeZone($gmt, 2));
var_dump($c->setTimeZone());
var_dump(intlcal_set_time_zone($c, 1, 2));
var_dump(intlcal_set_time_zone(1, $gmt));
Пример #14
0
 public function testGetFormatterDateException()
 {
     $timezoneNameList = \Functional\reject(DateTimeZone::listIdentifiers(), function ($timeZoneName) {
         return IntlTimeZone::fromDateTimeZone(new DateTimeZone($timeZoneName));
     });
     if (empty($timezoneNameList)) {
         $this->markTestSkipped('No unsupported timezones');
     }
     try {
         $timeZoneName = \Functional\first($timezoneNameList);
         $render = new CM_Frontend_Render();
         $render->getFormatterDate(IntlDateFormatter::SHORT, IntlDateFormatter::SHORT, null, new DateTimeZone($timeZoneName));
         $this->fail('Date formatter created with unsupported timezone');
     } catch (CM_Exception $ex) {
         $this->assertSame('Cannot create date formatter', $ex->getMessage());
     }
 }
<?php

ini_set("intl.error_level", E_WARNING);
var_dump(IntlTimeZone::getCanonicalID('Portugal', $isSystemId));
var_dump($isSystemId);
var_dump(IntlTimeZone::getCanonicalID('GMT +01:25', $isSystemId));
var_dump($isSystemId);
?>
==DONE==
Пример #16
0
<?php

ini_set("intl.error_level", E_WARNING);
$tz = IntlTimeZone::createDefault();
print_r($tz);
$tz = intltz_create_default();
print_r($tz);
?>
==DONE==
<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
date_default_timezone_set('Europe/Amsterdam');
$cal = intlcal_create_instance('Europe/Amsterdam');
print_R($cal->getTimeZone());
print_R($cal->getLocale(Locale::ACTUAL_LOCALE));
echo "\n";
$cal = intlcal_create_instance('Europe/Lisbon', null);
print_R($cal->getTimeZone());
print_R($cal->getLocale(Locale::ACTUAL_LOCALE));
echo "\n";
$cal = intlcal_create_instance(IntlTimeZone::createTimeZone('Europe/Lisbon'));
print_R($cal->getTimeZone());
print_R($cal->getLocale(Locale::ACTUAL_LOCALE));
echo "\n";
$cal = intlcal_create_instance(null, "pt");
print_R($cal->getTimeZone());
print_R($cal->getLocale(Locale::ACTUAL_LOCALE));
echo "\n";
$cal = intlcal_create_instance("Europe/Lisbon", "pt");
print_R($cal->getTimeZone());
print_R($cal->getLocale(Locale::ACTUAL_LOCALE));
echo "\n";
?>
==DONE==
<?php

ini_set("intl.error_level", E_WARNING);
var_dump(IntlTimeZone::fromDateTimeZone());
var_dump(IntlTimeZone::fromDateTimeZone(1, 2));
var_dump(IntlTimeZone::fromDateTimeZone('sdfds'));
var_dump(IntlTimeZone::fromDateTimeZone(new stdclass()));
$dt = new DateTime('2012-08-01 00:00:00 WEST');
var_dump(IntlTimeZone::fromDateTimeZone($dt->getTimeZone()));
var_dump(intltz_from_date_time_zone());
<?php

ini_set("intl.error_level", E_WARNING);
$enum = IntlTimeZone::createTimeZoneIDEnumeration(IntlTimeZone::TYPE_ANY);
$countAny = count(iterator_to_array($enum));
$enum = IntlTimeZone::createTimeZoneIDEnumeration(IntlTimeZone::TYPE_CANONICAL);
$countCanonical = count(iterator_to_array($enum));
$enum = IntlTimeZone::createTimeZoneIDEnumeration(IntlTimeZone::TYPE_CANONICAL_LOCATION);
$countCanonicalLocation = count(iterator_to_array($enum));
var_dump($countAny > $countCanonical);
var_dump($countCanonical > $countCanonicalLocation);
$enum = IntlTimeZone::createTimeZoneIDEnumeration(IntlTimeZone::TYPE_ANY, null, null);
$countAny2 = count(iterator_to_array($enum));
var_dump($countAny == $countAny2);
$enum = IntlTimeZone::createTimeZoneIDEnumeration(IntlTimeZone::TYPE_ANY, null, -3600000);
$values = iterator_to_array($enum);
print_r(array_values(array_intersect($values, array('Etc/GMT+1', 'Atlantic/Azores'))));
?>
==DONE==
Пример #20
0
<?php

ini_set("intl.error_level", E_WARNING);
$c = new IntlGregorianCalendar(NULL, 'pt_PT');
IntlTimeZone::getUnknown(1);
intltz_get_unknown(1);
Пример #21
0
<?php

ini_set("intl.error_level", E_WARNING);
var_dump(IntlTimeZone::getGMT(4));
    public function testFormatWithIntlTimeZone()
    {
        if (!class_exists('IntlTimeZone')) {
            $this->markTestSkipped('This test requires the IntlTimeZone class from the Intl extension.');
        }

        $formatter = $this->getDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, \IntlTimeZone::createTimeZone('GMT+03:00'), IntlDateFormatter::GREGORIAN, 'zzzz');

        $this->assertEquals('GMT+03:00', $formatter->format(0));
    }
Пример #23
0
<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
$tz = IntlTimeZone::getUnknown();
print_r($tz);
$tz = intltz_get_unknown();
print_r($tz);
?>
==DONE==
Пример #24
0
<?php

ini_set("intl.error_level", E_WARNING);
print_R(IntlTimeZone::getTZDataVersion());
echo "\n";
print_R(intltz_get_tz_data_version());
echo "\n";
?>
==DONE==
<?php

ini_set("intl.error_level", E_WARNING);
$tz = IntlTimeZone::createEnumeration(3600000);
var_dump(get_class($tz));
$count = count(iterator_to_array($tz));
var_dump($count > 20);
$tz->rewind();
var_dump(in_array('Europe/Amsterdam', iterator_to_array($tz)));
?>
==DONE==
Пример #26
0
 /**
  * @ignore
  */
 public function ITimeZone()
 {
     return IntlTimeZone::createTimeZone($this->name());
 }
 public function testFormatWithIntlTimeZone()
 {
     if (PHP_VERSION_ID < 50500 && !(extension_loaded('intl') && method_exists('IntlDateFormatter', 'setTimeZone'))) {
         $this->markTestSkipped('Only in PHP 5.5+ IntlDateFormatter allows to use DateTimeZone objects.');
     }
     $formatter = $this->getDateFormatter('en', IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, \IntlTimeZone::createTimeZone('GMT+03:00'), IntlDateFormatter::GREGORIAN, 'zzzz');
     $this->assertEquals('GMT+03:00', $formatter->format(0));
 }
<?php

ini_set("intl.error_level", E_WARNING);
$tz = IntlTimeZone::createEnumeration('NL');
var_dump(get_class($tz));
$count = count(iterator_to_array($tz));
var_dump($count >= 1);
$tz->rewind();
var_dump(in_array('Europe/Amsterdam', iterator_to_array($tz)));
?>
==DONE==
<?php

ini_set("intl.error_level", E_WARNING);
$enum = IntlTimeZone::createTimeZoneIDEnumeration(IntlTimeZone::TYPE_ANY, 'PT');
$values = iterator_to_array($enum);
var_dump(in_array('Europe/Lisbon', $values));
var_dump(in_array('Atlantic/Azores', $values));
$enum = IntlTimeZone::createTimeZoneIDEnumeration(IntlTimeZone::TYPE_ANY, 'PT', null);
$values2 = iterator_to_array($enum);
var_dump($values2 == $values);
?>
==DONE==
Пример #30
0
<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
$intlcal = IntlCalendar::createInstance('Europe/Amsterdam');
print_r($intlcal->getTimeZone()->getID());
echo "\n";
var_dump($intlcal->get(IntlCalendar::FIELD_ZONE_OFFSET));
$intlcal->setTimeZone(IntlTimeZone::getGMT());
print_r($intlcal->getTimeZone()->getID());
echo "\n";
var_dump($intlcal->get(IntlCalendar::FIELD_ZONE_OFFSET));
intlcal_set_time_zone($intlcal, IntlTimeZone::createTimeZone('GMT+05:30'));
print_r($intlcal->getTimeZone()->getID());
echo "\n";
var_dump($intlcal->get(IntlCalendar::FIELD_ZONE_OFFSET));
?>
==DONE==