/**
  * @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']];
 }
Exemple #2
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;
 }
 /**
  * @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);
 }
<?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==
Exemple #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]));
 }
<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
date_default_timezone_set('Europe/Lisbon');
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')));
}
do_test(IntlTimeZone::createTimeZone('CET'));
do_test(IntlTimeZone::createTimeZone('Europe/Amsterdam'));
do_test(IntlTimeZone::createTimeZone('GMT+0405'), true);
    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));
    }
 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));
 }
Exemple #9
0
 /**
  * @ignore
  */
 public function ITimeZone()
 {
     return IntlTimeZone::createTimeZone($this->name());
 }
<?php

ini_set("intl.error_level", E_WARNING);
ini_set("date.timezone", 'Atlantic/Azores');
$ts = strtotime('2012-01-01 00:00:00 UTC');
//should use Atlantic/Azores
$df = new IntlDateFormatter('es_ES', 0, 0, NULL);
echo $df->format($ts), "\n";
$df = new IntlDateFormatter('es_ES', 0, 0, 'Europe/Amsterdam');
echo $df->format($ts), "\n";
$df = new IntlDateFormatter('es_ES', 0, 0, new DateTimeZone('Europe/Lisbon'));
echo $df->format($ts), "\n";
$df = new IntlDateFormatter('es_ES', 0, 0, IntlTimeZone::createTimeZone('America/New_York'));
echo $df->format($ts), "\n";
//time zone has priority
$df = new IntlDateFormatter('es_ES', 0, 0, 'Europe/Amsterdam', new IntlGregorianCalendar('Europe/Lisbon'));
echo $df->format($ts), "\n";
//calendar has priority
$df = new IntlDateFormatter('es_ES', 0, 0, NULL, new IntlGregorianCalendar('Europe/Lisbon'));
echo $df->format($ts), "\n";
$df = new IntlDateFormatter('es_ES', 0, 0, 'Europe/Amsterdam', 0);
echo $df->format($ts), "\n";
 public function testFormatWithIntlTimeZone()
 {
     $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);
ini_set("intl.default_locale", "pt_PT");
ini_set("date.timezone", 'Atlantic/Azores');
$ts = strtotime('2012-01-01 00:00:00 UTC');
function d(IntlDateFormatter $df)
{
    global $ts;
    echo $df->format($ts), "\n";
    var_dump($df->getTimeZoneID(), $df->getTimeZone()->getID());
    echo "\n";
}
$df = new IntlDateFormatter('pt_PT', 0, 0, 'Europe/Minsk');
d($df);
$df->setTimeZone(NULL);
d($df);
$df->setTimeZone('Europe/Madrid');
d($df);
$df->setTimeZone(IntlTimeZone::createTimeZone('Europe/Paris'));
d($df);
$df->setTimeZone(new DateTimeZone('Europe/Amsterdam'));
d($df);
?>
==DONE==
<?php

ini_set("intl.error_level", E_WARNING);
$tz = IntlTimeZone::createTimeZone('Etc/Unknown');
var_dump($tz->toDateTimeZone(''));
try {
    var_dump($tz->toDateTimeZone());
} catch (Exception $e) {
    var_dump($e->getMessage());
}
var_dump(intltz_to_date_time_zone());
var_dump(intltz_to_date_time_zone(1));
<?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);
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==
 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);
$tz1 = IntlTimeZone::createTimeZone('Europe/Amsterdam');
print_r($tz1);
print_r(clone $tz1);
//clone non-owned object
$gmt = IntlTimeZone::getGMT();
print_r($gmt);
print_r(clone $gmt);
?>
==DONE==
<?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);
$lsb = IntlTimeZone::createTimeZone('Europe/Lisbon');
$prt = IntlTimeZone::createTimeZone('Portugal');
$azo = IntlTimeZone::createTimeZone('Atlantic/Azores');
echo "Europe/Lisbon has same rules as itself:\n";
var_dump($lsb->hasSameRules($lsb));
echo "\nEurope/Lisbon has same rules as Portugal:\n";
var_dump($lsb->hasSameRules($prt));
echo "\nEurope/Lisbon has same rules as Atlantic/Azores:\n";
var_dump(intltz_has_same_rules($lsb, $azo));
?>
==DONE==