예제 #1
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']];
 }
 /**
  * @return array
  */
 protected function getFreeWeekDays()
 {
     $freeWeekDays = [];
     $calendar = \IntlCalendar::createInstance($this->tz, $this->locale);
     foreach ($this->intlMapping as $intlDay => $manipulatorDay) {
         $dayOfWeekType = $calendar->getDayOfWeekType($intlDay);
         $weekEndTransition = $calendar->getWeekendTransition($intlDay);
         if (\IntlCalendar::DOW_TYPE_WEEKEND === $dayOfWeekType || \IntlCalendar::DOW_TYPE_WEEKEND_OFFSET === $dayOfWeekType && 0 === $weekEndTransition || \IntlCalendar::DOW_TYPE_WEEKEND_CEASE === $dayOfWeekType && 86400000 === $weekEndTransition) {
             $freeWeekDays[] = $manipulatorDay;
         }
     }
     return $freeWeekDays;
 }
<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "pt_PT");
ini_set("date.timezone", "Europe/Lisbon");
$cal = IntlCalendar::fromDateTime('2012-01-01 00:00:00');
//Europe/Lisbon
echo IntlDateFormatter::formatObject($cal), "\n";
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL), "\n";
echo IntlDateFormatter::formatObject($cal, null, "en-US"), "\n";
echo IntlDateFormatter::formatObject($cal, array(IntlDateFormatter::SHORT, IntlDateFormatter::FULL), "en-US"), "\n";
echo IntlDateFormatter::formatObject($cal, 'E y-MM-d HH,mm,ss.SSS v', "en-US"), "\n";
$cal = IntlCalendar::fromDateTime('2012-01-01 05:00:00+03:00');
echo datefmt_format_object($cal, IntlDateFormatter::FULL), "\n";
$cal = IntlCalendar::createInstance(null, 'en-US@calendar=islamic-civil');
$cal->setTime(strtotime('2012-01-01 00:00:00') * 1000.0);
echo IntlDateFormatter::formatObject($cal), "\n";
echo IntlDateFormatter::formatObject($cal, IntlDateFormatter::FULL, "en-US"), "\n";
?>
==DONE==
예제 #4
0
<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
$intlcal = IntlCalendar::createInstance('UTC');
$intlcal->clear();
var_dump($intlcal->set(2012, 1, 29));
var_dump($intlcal->getTime(), strtotime('2012-02-29 00:00:00 +0000') * 1000.0);
//two minutes to midnight!
var_dump($intlcal->set(2012, 1, 29, 23, 58));
var_dump($intlcal->getTime(), strtotime('2012-02-29 23:58:00 +0000') * 1000.0);
var_dump($intlcal->set(2012, 1, 29, 23, 58, 31));
var_dump($intlcal->getTime(), strtotime('2012-02-29 23:58:31 +0000') * 1000.0);
?>
==DONE==
<?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->getCalendar(), $df->getCalendarObject()->getType(), $df->getCalendarObject()->getTimeZone()->getId());
    echo "\n";
}
$df = new IntlDateFormatter('fr@calendar=islamic', 0, 0, 'Europe/Minsk');
d($df);
//changing the calendar with a cal type should not change tz
$df->setCalendar(IntlDateFormatter::TRADITIONAL);
d($df);
//but changing with an actual calendar should
$cal = IntlCalendar::createInstance("UTC");
$df->setCalendar($cal);
d($df);
?>
==DONE==
<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
$intlcal1 = new IntlGregorianCalendar(2012, 1, 29, 16, 59, 59);
$intlcal2 = IntlCalendar::createInstance(null, '@calendar=japanese');
$intlcal3 = new IntlGregorianCalendar(2012, 1, 29, 17, 00, 00);
$intlcal2->setTime($intlcal1->getTime());
var_dump($intlcal2->getType());
var_dump("1 eq 1", $intlcal1->equals($intlcal1));
var_dump("1 eq 2", $intlcal1->equals($intlcal2));
var_dump("1 before 2", $intlcal1->before($intlcal2));
var_dump("1 after 2", $intlcal1->after($intlcal2));
var_dump("1 eq 3", $intlcal1->equals($intlcal3));
var_dump("1 before 3", $intlcal1->before($intlcal3));
var_dump("1 after 3", $intlcal1->after($intlcal3));
var_dump("3 eq 2", intlcal_equals($intlcal3, $intlcal2));
var_dump("3 before 2", intlcal_before($intlcal3, $intlcal2));
var_dump("3 after 2", intlcal_after($intlcal3, $intlcal2));
?>
==DONE==
예제 #7
0
 public function it_should_convert_intl_calendar()
 {
     if (!class_exists('\\IntlCalendar')) {
         return;
     }
     $this::import(\IntlCalendar::createInstance(null, 'en_US@calendar=persian'))->shouldHaveType('Danhunsaker\\Calends\\Calends');
     $this->convert('IntlCalendar')->shouldHaveKey('duration');
 }
예제 #8
0
function getFirstWeekday()
{
    // this works on Linux
    // http://stackoverflow.com/questions/727471/how-do-i-get-the-first-day-of-the-week-for-the-current-locale-php-l8n
    $weekday = exec('locale first_weekday');
    if ($weekday) {
        // Returns Monday=2, but we need 1 for Monday
        // see http://man7.org/linux/man-pages/man5/locale.5.html
        return --$weekday;
    }
    // This would work in PHP 5.5
    if (class_exists('IntlCalendar')) {
        $cal = IntlCalendar::createInstance();
        return $cal->getFirstDayOfWeek() == IntlCalendar::DOW_MONDAY ? 1 : 0;
    }
    // default to Monday as it's default for "World" in CLDR's supplemental data
    return 1;
}
예제 #9
0
 public function testConfigureOptionsWithIntlCalendar()
 {
     $this->type->configureOptions($resolver = new OptionsResolver());
     $this->assertSame(['path' => $path = 'path_value', 'calendar' => $calendar = \IntlCalendar::createInstance(), 'date_format' => \IntlDateFormatter::MEDIUM, 'lenient' => false, 'pattern' => null, 'timezone' => null, 'time_format' => \IntlDateFormatter::MEDIUM], $resolver->resolve(['path' => $path, 'calendar' => $calendar]));
 }
<?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');
$cal = new IntlGregorianCalendar('UTC', NULL);
$df = new IntlDateFormatter('es_ES', 0, 0, NULL, $cal);
echo $df->format($ts), "\n";
$cal = IntlCalendar::createInstance('UTC', 'en@calendar=islamic');
$df = new IntlDateFormatter('es_ES', 0, 0, NULL, $cal);
echo $df->format($ts), "\n";
//override calendar's timezone
$cal = new IntlGregorianCalendar('UTC', NULL);
$df = new IntlDateFormatter('es_ES', 0, 0, 'Europe/Madrid', $cal);
echo $df->format($ts), "\n";
//default calendar is gregorian
$df = new IntlDateFormatter('es_ES@calendar=islamic', 0, 0);
echo $df->format($ts), "\n";
//try now with traditional
$df = new IntlDateFormatter('es_ES@calendar=islamic', 0, 0, NULL, IntlDateFormatter::TRADITIONAL);
echo $df->format($ts), "\n";
//the timezone can be overridden when not specifying a calendar
$df = new IntlDateFormatter('es_ES@calendar=islamic', 0, 0, 'UTC', IntlDateFormatter::TRADITIONAL);
echo $df->format($ts), "\n";
$df = new IntlDateFormatter('es_ES', 0, 0, 'UTC', 0);
echo $df->format($ts), "\n";
?>
==DONE==
예제 #11
0
<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
$intlcal = IntlCalendar::createInstance('GMT+00:01');
print_r($intlcal->getTimeZone());
print_r(intlcal_get_time_zone($intlcal));
?>
==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));
/* passing NULL has no effect */
$intlcal->setTimeZone(null);
print_r($intlcal->getTimeZone()->getID());
echo "\n";
var_dump($intlcal->get(IntlCalendar::FIELD_ZONE_OFFSET));
?>
==DONE==
ini_set("intl.default_locale", "pt_PT");
ini_set("date.timezone", "Europe/Lisbon");
var_dump(IntlDateFormatter::formatObject());
var_dump(IntlDateFormatter::formatObject(1));
var_dump(IntlDateFormatter::formatObject(new stdclass()));
class A extends IntlCalendar
{
    function __construct()
    {
    }
}
var_dump(IntlDateFormatter::formatObject(new A()));
class B extends DateTime
{
    function __construct()
    {
    }
}
var_dump(IntlDateFormatter::formatObject(new B()));
$cal = IntlCalendar::createInstance();
var_dump(IntlDateFormatter::formatObject($cal, -2));
var_dump(IntlDateFormatter::formatObject($cal, array()));
var_dump(IntlDateFormatter::formatObject($cal, array(1, 2, 3)));
var_dump(IntlDateFormatter::formatObject($cal, array(array(), 1)));
var_dump(IntlDateFormatter::formatObject($cal, array(1, -2)));
var_dump(IntlDateFormatter::formatObject($cal, ""));
var_dump(IntlDateFormatter::formatObject($cal, "YYYY", array()));
?>
==DONE==

<?php

ini_set("intl.error_level", E_WARNING);
class X extends IntlTimeZone
{
    function __construct()
    {
    }
}
var_dump(IntlCalendar::createInstance(1, 2, 3));
var_dump(intlcal_create_instance(1, 2, 3));
var_dump(intlcal_create_instance(new X(), NULL));
var_dump(intlcal_create_instance(NULL, array()));
예제 #15
0
<?php

ini_set("intl.error_level", E_WARNING);
ini_set("intl.default_locale", "nl");
$intlcal = IntlCalendar::createInstance();
VAR_DUMP($intlcal->getType());
$intlcal = IntlCalendar::createInstance(null, "nl_NL@calendar=hebrew");
VAR_DUMP(intlcal_get_type($intlcal));
?>
==DONE==
예제 #16
0
 public function it_should_import_intl_calendar()
 {
     if (!class_exists('\\IntlCalendar')) {
         return;
     }
     $this::import(\IntlCalendar::createInstance(NULL, 'en_US@calendar=persian'))->shouldHaveType('Danhunsaker\\Calends\\Calends');
 }