当前位置: 首页>>代码示例>>PHP>>正文


PHP intl_get_error_code函数代码示例

本文整理汇总了PHP中intl_get_error_code函数的典型用法代码示例。如果您正苦于以下问题:PHP intl_get_error_code函数的具体用法?PHP intl_get_error_code怎么用?PHP intl_get_error_code使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了intl_get_error_code函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: ut_main

function ut_main()
{
    $locale_arr = array('en_US_CA');
    $datetype_arr = array(IntlDateFormatter::FULL, IntlDateFormatter::LONG, IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
    $res_str = '';
    $text_arr = array("Sunday, September 18, 3039 4:06:40 PM PT", "Thursday, December 18, 1969 8:49:59 AM PST", "12/18/69 8:49 AM", "20111218 08:49 AM", "19691218 08:49 AM");
    foreach ($text_arr as $text_entry) {
        $res_str .= "\n------------\n";
        $res_str .= "\nInput text is : {$text_entry}";
        $res_str .= "\n------------";
        foreach ($locale_arr as $locale_entry) {
            $res_str .= "\nLocale is : {$locale_entry}";
            $res_str .= "\n------------";
            foreach ($datetype_arr as $datetype_entry) {
                $res_str .= "\ndatetype = {$datetype_entry} ,timetype ={$datetype_entry}";
                $fmt = ut_datefmt_create($locale_entry, $datetype_entry, $datetype_entry);
                $pos = 0;
                $parsed = ut_datefmt_parse($fmt, $text_entry, $pos);
                if (intl_get_error_code() == U_ZERO_ERROR) {
                    $res_str .= "\nParsed text is : {$parsed}; Position = {$pos}";
                } else {
                    $res_str .= "\nError while parsing as: '" . intl_get_error_message() . "'; Position = {$pos}";
                }
            }
        }
    }
    $res_str .= "\n";
    return $res_str;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:29,代码来源:dateformat_parse_timestamp_parsepos.php

示例2: buildForm

 /**
  * {@inheritdoc}
  */
 public function buildForm(FormBuilderInterface $builder, array $options)
 {
     $dateFormat = is_int($options['format']) ? $options['format'] : self::DEFAULT_FORMAT;
     $timeFormat = \IntlDateFormatter::NONE;
     $calendar = \IntlDateFormatter::GREGORIAN;
     $pattern = is_string($options['format']) ? $options['format'] : null;
     if (!in_array($dateFormat, self::$acceptedFormats, true)) {
         throw new InvalidOptionsException('The "format" option must be one of the IntlDateFormatter constants (FULL, LONG, MEDIUM, SHORT) or a string representing a custom format.');
     }
     if (null !== $pattern && (false === strpos($pattern, 'y') || false === strpos($pattern, 'M') || false === strpos($pattern, 'd'))) {
         throw new InvalidOptionsException(sprintf('The "format" option should contain the letters "y", "M" and "d". Its current value is "%s".', $pattern));
     }
     if ('single_text' === $options['widget']) {
         $builder->addViewTransformer(new DateTimeToLocalizedStringTransformer($options['model_timezone'], $options['view_timezone'], $dateFormat, $timeFormat, $calendar, $pattern));
     } else {
         $yearOptions = $monthOptions = $dayOptions = array('error_bubbling' => true);
         $formatter = new \IntlDateFormatter(\Locale::getDefault(), $dateFormat, $timeFormat, null, $calendar, $pattern);
         // new \intlDateFormatter may return null instead of false in case of failure, see https://bugs.php.net/bug.php?id=66323
         if (!$formatter) {
             throw new InvalidOptionsException(intl_get_error_message(), intl_get_error_code());
         }
         $formatter->setLenient(false);
         if ('choice' === $options['widget']) {
             // Only pass a subset of the options to children
             $yearOptions['choices'] = $this->formatTimestamps($formatter, '/y+/', $this->listYears($options['years']));
             $yearOptions['choices_as_values'] = true;
             $yearOptions['placeholder'] = $options['placeholder']['year'];
             $yearOptions['choice_translation_domain'] = $options['choice_translation_domain']['year'];
             $monthOptions['choices'] = $this->formatTimestamps($formatter, '/[M|L]+/', $this->listMonths($options['months']));
             $monthOptions['choices_as_values'] = true;
             $monthOptions['placeholder'] = $options['placeholder']['month'];
             $monthOptions['choice_translation_domain'] = $options['choice_translation_domain']['month'];
             $dayOptions['choices'] = $this->formatTimestamps($formatter, '/d+/', $this->listDays($options['days']));
             $dayOptions['choices_as_values'] = true;
             $dayOptions['placeholder'] = $options['placeholder']['day'];
             $dayOptions['choice_translation_domain'] = $options['choice_translation_domain']['day'];
         }
         // Append generic carry-along options
         foreach (array('required', 'translation_domain') as $passOpt) {
             $yearOptions[$passOpt] = $monthOptions[$passOpt] = $dayOptions[$passOpt] = $options[$passOpt];
         }
         $builder->add('year', self::$widgets[$options['widget']], $yearOptions)->add('month', self::$widgets[$options['widget']], $monthOptions)->add('day', self::$widgets[$options['widget']], $dayOptions)->addViewTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['view_timezone'], array('year', 'month', 'day')))->setAttribute('formatter', $formatter);
     }
     if ('string' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToStringTransformer($options['model_timezone'], $options['model_timezone'], 'Y-m-d')));
     } elseif ('timestamp' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToTimestampTransformer($options['model_timezone'], $options['model_timezone'])));
     } elseif ('array' === $options['input']) {
         $builder->addModelTransformer(new ReversedTransformer(new DateTimeToArrayTransformer($options['model_timezone'], $options['model_timezone'], array('year', 'month', 'day'))));
     }
 }
开发者ID:ron-testam,项目名称:symfony,代码行数:54,代码来源:DateType.php

示例3: convert

 /**
  * Parse data string and convert to the \DateTime object.
  *
  * @param string          $value
  * @param string|int|null $dateType
  * @param string|int|null $timeType
  * @param string|null     $locale
  * @param string|null     $timeZone
  * @param string|null     $pattern
  *
  * @return \DateTime|false
  */
 public function convert($value, $dateType = null, $timeType = null, $locale = null, $timeZone = null, $pattern = null)
 {
     if (!$locale) {
         $locale = $this->localeSettings->getLocale();
     }
     if (!$timeZone) {
         $timeZone = $this->localeSettings->getTimeZone();
     }
     if ($value) {
         $formatter = $this->getFormatter($dateType, $timeType, $locale, $timeZone, $pattern);
         $timestamp = $formatter->parse($value);
         if (intl_get_error_code() === 0) {
             return $this->getDateTime($timestamp);
         }
     }
     return false;
 }
开发者ID:antrampa,项目名称:platform,代码行数:29,代码来源:ExcelDateTimeTypeFormatter.php

示例4: ut_main

function ut_main()
{
    $res_str = '';
    $forms = array(Normalizer::FORM_C, Normalizer::FORM_D, Normalizer::FORM_KC, Normalizer::FORM_KD, Normalizer::NONE);
    $forms_str = array(Normalizer::FORM_C => 'UNORM_FORM_C', Normalizer::FORM_D => 'UNORM_FORM_D', Normalizer::FORM_KC => 'UNORM_FORM_KC', Normalizer::FORM_KD => 'UNORM_FORM_KD', Normalizer::NONE => 'UNORM_NONE');
    /* just make sure all the form constants are defined as in the api spec */
    if (Normalizer::FORM_C != Normalizer::NFC || Normalizer::FORM_D != Normalizer::NFD || Normalizer::FORM_KC != Normalizer::NFKC || Normalizer::FORM_KD != Normalizer::NFKD || Normalizer::NONE == Normalizer::FORM_C) {
        $res_str .= "Invalid normalization form declarations!\n";
    }
    $char_a_diaeresis = "ä";
    // 'LATIN SMALL LETTER A WITH DIAERESIS' (U+00E4)
    $char_a_ring = "å";
    // 'LATIN SMALL LETTER A WITH RING ABOVE' (U+00E5)
    $char_o_diaeresis = "ö";
    // 'LATIN SMALL LETTER O WITH DIAERESIS' (U+00F6)
    $char_angstrom_sign = "Å";
    // 'ANGSTROM SIGN' (U+212B)
    $char_A_ring = "Å";
    // 'LATIN CAPITAL LETTER A WITH RING ABOVE' (U+00C5)
    $char_ohm_sign = "Ω";
    // 'OHM SIGN' (U+2126)
    $char_omega = "Ω";
    // 'GREEK CAPITAL LETTER OMEGA' (U+03A9)
    $char_combining_ring_above = "̊";
    // 'COMBINING RING ABOVE' (U+030A)
    $char_fi_ligature = "fi";
    // 'LATIN SMALL LIGATURE FI' (U+FB01)
    $char_long_s_dot = "ẛ";
    // 'LATIN SMALL LETTER LONG S WITH DOT ABOVE' (U+1E9B)
    $strs = array('ABC', $char_a_diaeresis . '||' . $char_a_ring . '||' . $char_o_diaeresis, $char_angstrom_sign . '||' . $char_A_ring . '||' . 'A' . $char_combining_ring_above, $char_ohm_sign . '||' . $char_omega, $char_fi_ligature, $char_long_s_dot);
    foreach ($forms as $form) {
        foreach ($strs as $str) {
            $str_norm = ut_norm_normalize($str, $form);
            $error_code = intl_get_error_code();
            $error_message = intl_get_error_message();
            $str_hex = urlencode($str);
            $str_norm_hex = urlencode($str_norm);
            $res_str .= "'{$str_hex}' normalized to form '{$forms_str[$form]}' is '{$str_norm_hex}'" . "\terror info: '{$error_message}' ({$error_code})\n" . "";
            $is_norm = ut_norm_is_normalized($str, $form);
            $error_code = intl_get_error_code();
            $error_message = intl_get_error_message();
            $res_str .= "\t\tis in form '{$forms_str[$form]}'? = " . ($is_norm ? "yes" : "no") . "\terror info: '{$error_message}' ({$error_code})\n" . "";
        }
    }
    return $res_str;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:46,代码来源:normalizer_normalize.php

示例5: reverseTransform

 /**
  * Transforms a localized date string/array into a normalized date.
  *
  * @param  string|array $value Localized date string/array
  * @return DateTime Normalized date
  */
 public function reverseTransform($value)
 {
     $inputTimezone = $this->getOption('input_timezone');
     if (!is_string($value)) {
         throw new \InvalidArgumentException(sprintf('Expected argument of type string, %s given', gettype($value)));
     }
     $timestamp = $this->getIntlDateFormatter()->parse($value);
     if (intl_get_error_code() != 0) {
         throw new TransformationFailedException(intl_get_error_message());
     }
     // read timestamp into DateTime object - the formatter delivers in UTC
     $dateTime = new \DateTime(sprintf('@%s UTC', $timestamp));
     if ($inputTimezone != 'UTC') {
         $dateTime->setTimezone(new \DateTimeZone($inputTimezone));
     }
     return $dateTime;
 }
开发者ID:skoop,项目名称:symfony-sandbox,代码行数:23,代码来源:DateTimeToLocalizedStringTransformer.php

示例6: ut_main

function ut_main()
{
    $locale_arr = array('en_US_CA');
    $datetype_arr = array(IntlDateFormatter::FULL, IntlDateFormatter::LONG, IntlDateFormatter::MEDIUM, IntlDateFormatter::SHORT, IntlDateFormatter::NONE);
    $res_str = '';
    $text_arr = array(array("Sunday, September 18, 2039 4:06:40 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::FULL), array("Wednesday, December 17, 1969 6:40:00 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::FULL), array("Thursday, December 18, 1969 8:49:59 PM PST", IntlDateFormatter::FULL, IntlDateFormatter::FULL), array("December 18, 1969 8:49:59 AM PST", IntlDateFormatter::LONG, IntlDateFormatter::FULL), array("12/18/69 8:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::SHORT), array("19691218 08:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::SHORT), array("Sunday, September 18, 2039 4:06:40 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::NONE), array("Sunday, September 18, 2039 4:06:40 PM PT", IntlDateFormatter::FULL, IntlDateFormatter::SHORT), array("December 18, 1969 8:49:59 AM PST", IntlDateFormatter::LONG, IntlDateFormatter::NONE), array("December 18, 1969 8:49:59 AM PST", IntlDateFormatter::LONG, IntlDateFormatter::SHORT), array("12/18/69 8:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::LONG), array("19691218 08:49 AM", IntlDateFormatter::SHORT, IntlDateFormatter::LONG));
    foreach ($text_arr as $text_entry) {
        $fmt = ut_datefmt_create('en_US_CA', $text_entry[1], $text_entry[2]);
        $parse_pos = 0;
        $parsed = ut_datefmt_parse($fmt, $text_entry[0], $parse_pos);
        $res_str .= "\nInput text : {$text_entry[0]} ; DF = {$text_entry[1]}; TF = {$text_entry[2]}";
        if (intl_get_error_code() != U_ZERO_ERROR) {
            $res_str .= "\nError : " . intl_get_error_message();
        }
        $res_str .= "\nParsed: {$parsed}; parse_pos : {$parse_pos}\n";
    }
    return $res_str;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:18,代码来源:dateformat_parse.php

示例7: format

 /**
  * Formats the message with the help of php intl extension.
  * 
  * @param string $locale
  * @param string $message
  * @param array(string=>mixed) $parameters
  * @return string
  * @throws CannotInstantiateFormatterException If the message pattern cannot be used.
  * @throws CannotFormatException If an error occurs during formatting.
  */
 public function format($locale, $message, array $parameters)
 {
     if (empty($message)) {
         // Empty strings are not accepted as message pattern by the \MessageFormatter.
         return $message;
     }
     try {
         $formatter = new \MessageFormatter($locale, $message);
     } catch (\Exception $e) {
         throw new CannotInstantiateFormatterException($e->getMessage(), $e->getCode(), $e);
     }
     if (!$formatter) {
         throw new CannotInstantiateFormatterException(intl_get_error_message(), intl_get_error_code());
     }
     $result = $formatter->format($parameters);
     if ($result === false) {
         throw new CannotFormatException($formatter->getErrorMessage(), $formatter->getErrorCode());
     }
     return $result;
 }
开发者ID:webfactory,项目名称:icu-translation-bundle,代码行数:30,代码来源:IntlFormatter.php

示例8: reverseTransform

 /**
  * Transforms a localized date string/array into a normalized date.
  *
  * @param  string|array $value Localized date string/array
  * @return DateTime Normalized date
  */
 public function reverseTransform($value)
 {
     $inputTimezone = $this->getOption('input_timezone');
     if (!is_string($value)) {
         throw new UnexpectedTypeException($value, 'string');
     }
     if ('' === $value) {
         return null;
     }
     $timestamp = $this->getIntlDateFormatter()->parse($value);
     if (intl_get_error_code() != 0) {
         throw new TransformationFailedException(intl_get_error_message());
     }
     // read timestamp into DateTime object - the formatter delivers in UTC
     $dateTime = new \DateTime(sprintf('@%s UTC', $timestamp));
     if ('UTC' != $inputTimezone) {
         $dateTime->setTimezone(new \DateTimeZone($inputTimezone));
     }
     return $dateTime;
 }
开发者ID:yproximite,项目名称:symfony-legacy-form,代码行数:26,代码来源:DateTimeToLocalizedStringTransformer.php

示例9: format

 /**
  * {@inheritdoc}
  */
 public function format($value, array $options = array())
 {
     if (null === $value) {
         return $options['null_value'];
     }
     if (!$value instanceof \DateTime) {
         throw FormatterException::invalidType($this, $value, 'DateTime instance');
     }
     $dateTime = clone $value;
     if ('UTC' !== $options['time_zone']) {
         $dateTime->setTimezone(new \DateTimeZone('UTC'));
     }
     $formatter = new \IntlDateFormatter(\Locale::getDefault(), $options['date_format'], $options['time_format'], $options['time_zone'], $options['calendar'], $options['pattern']);
     $formatter->setLenient(false);
     $value = $formatter->format((int) $dateTime->format('U'));
     if (intl_is_failure(intl_get_error_code())) {
         throw FormatterException::intlError($this, intl_get_error_message());
     }
     $value = preg_replace('~GMT\\+00:00$~', 'GMT', $value);
     return $value;
 }
开发者ID:jfsimon,项目名称:datagrid,代码行数:24,代码来源:DateTimeFormatter.php

示例10: createDateTime

 /**
  * Creates date time object from date string
  *
  * @param string $dateString
  * @param string|null $timeZone
  * @param string $format
  * @throws \Exception
  * @return \DateTime
  */
 private function createDateTime($dateString, $timeZone = null, $format = 'yyyy-MM-dd')
 {
     $pattern = $format ? $format : null;
     if (!$timeZone) {
         $timeZone = date_default_timezone_get();
     }
     $calendar = \IntlDateFormatter::GREGORIAN;
     $intlDateFormatter = new \IntlDateFormatter(\Locale::getDefault(), \IntlDateFormatter::NONE, \IntlDateFormatter::NONE, $timeZone, $calendar, $pattern);
     $intlDateFormatter->setLenient(false);
     $timestamp = $intlDateFormatter->parse($dateString);
     if (intl_get_error_code() != 0) {
         throw new \Exception(intl_get_error_message());
     }
     // read timestamp into DateTime object - the formatter delivers in UTC
     $dateTime = new \DateTime(sprintf('@%s UTC', $timestamp));
     if ('UTC' !== $timeZone) {
         try {
             $dateTime->setTimezone(new \DateTimeZone($timeZone));
         } catch (\Exception $e) {
             throw new \Exception($e->getMessage(), $e->getCode(), $e);
         }
     }
     return $dateTime;
 }
开发者ID:noglitchyo,项目名称:pim-community-dev,代码行数:33,代码来源:DateRangeTypeTest.php

示例11: format

 /**
  * Formats a message via [ICU message format](http://userguide.icu-project.org/formatparse/messages)
  *
  * It uses the PHP intl extension's [MessageFormatter](http://www.php.net/manual/en/class.messageformatter.php)
  * and works around some issues.
  * If PHP intl is not installed a fallback will be used that supports a subset of the ICU message format.
  *
  * @param string $pattern The pattern string to insert parameters into.
  * @param array $params The array of name value pairs to insert into the format string.
  * @param string $language The locale to use for formatting locale-dependent parts
  * @return string|boolean The formatted pattern string or `FALSE` if an error occurred
  */
 public function format($pattern, $params, $language)
 {
     $this->_errorCode = 0;
     $this->_errorMessage = '';
     if ($params === []) {
         return $pattern;
     }
     if (!class_exists('MessageFormatter', false)) {
         return $this->fallbackFormat($pattern, $params, $language);
     }
     if (version_compare(PHP_VERSION, '5.5.0', '<') || version_compare(INTL_ICU_VERSION, '4.8', '<')) {
         // replace named arguments
         $pattern = $this->replaceNamedArguments($pattern, $params, $newParams);
         $params = $newParams;
     }
     $formatter = new \MessageFormatter($language, $pattern);
     if ($formatter === null) {
         $this->_errorCode = intl_get_error_code();
         $this->_errorMessage = "Message pattern is invalid: " . intl_get_error_message();
         return false;
     }
     $result = $formatter->format($params);
     if ($result === false) {
         $this->_errorCode = $formatter->getErrorCode();
         $this->_errorMessage = $formatter->getErrorMessage();
         return false;
     } else {
         return $result;
     }
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:42,代码来源:MessageFormatter.php

示例12: format

 /**
  * Formats a message via [ICU message format](http://userguide.icu-project.org/formatparse/messages)
  *
  * It uses the PHP intl extension's [MessageFormatter](http://www.php.net/manual/en/class.messageformatter.php)
  * and works around some issues.
  * If PHP intl is not installed a fallback will be used that supports a subset of the ICU message format.
  *
  * @param string $pattern The pattern string to insert parameters into.
  * @param array $params The array of name value pairs to insert into the format string.
  * @param string $language The locale to use for formatting locale-dependent parts
  * @return string|bool The formatted pattern string or `FALSE` if an error occurred
  */
 public function format($pattern, $params, $language)
 {
     $this->_errorCode = 0;
     $this->_errorMessage = '';
     if ($params === []) {
         return $pattern;
     }
     if (!class_exists('MessageFormatter', false)) {
         return $this->fallbackFormat($pattern, $params, $language);
     }
     // replace named arguments (https://github.com/yiisoft/yii2/issues/9678)
     $newParams = [];
     $pattern = $this->replaceNamedArguments($pattern, $params, $newParams);
     $params = $newParams;
     try {
         $formatter = new \MessageFormatter($language, $pattern);
         if ($formatter === null) {
             // formatter may be null in PHP 5.x
             $this->_errorCode = intl_get_error_code();
             $this->_errorMessage = 'Message pattern is invalid: ' . intl_get_error_message();
             return false;
         }
     } catch (\IntlException $e) {
         // IntlException is thrown since PHP 7
         $this->_errorCode = $e->getCode();
         $this->_errorMessage = 'Message pattern is invalid: ' . $e->getMessage();
         return false;
     } catch (\Exception $e) {
         // Exception is thrown by HHVM
         $this->_errorCode = $e->getCode();
         $this->_errorMessage = 'Message pattern is invalid: ' . $e->getMessage();
         return false;
     }
     $result = $formatter->format($params);
     if ($result === false) {
         $this->_errorCode = $formatter->getErrorCode();
         $this->_errorMessage = $formatter->getErrorMessage();
         return false;
     } else {
         return $result;
     }
 }
开发者ID:arogachev,项目名称:yii2,代码行数:54,代码来源:MessageFormatter.php

示例13: testParseIntl

 /**
  * @dataProvider parseProvider
  */
 public function testParseIntl($value, $expected, $message = '')
 {
     $this->skipIfIntlExtensionIsNotLoaded();
     $this->skipIfICUVersionIsTooOld();
     $formatter = $this->getIntlFormatterWithDecimalStyle();
     $parsedValue = $formatter->parse($value, \NumberFormatter::TYPE_DOUBLE);
     $this->assertSame($expected, $parsedValue, $message);
     if ($expected === false) {
         $errorCode = StubIntl::U_PARSE_ERROR;
         $errorMessage = 'Number parsing failed: U_PARSE_ERROR';
     } else {
         $errorCode = StubIntl::U_ZERO_ERROR;
         $errorMessage = 'U_ZERO_ERROR';
     }
     $this->assertSame($errorMessage, intl_get_error_message());
     $this->assertSame($errorCode, intl_get_error_code());
     $this->assertSame($errorCode > 0, intl_is_failure(intl_get_error_code()));
     $this->assertSame($errorMessage, $formatter->getErrorMessage());
     $this->assertSame($errorCode, $formatter->getErrorCode());
     $this->assertSame($errorCode > 0, intl_is_failure($formatter->getErrorCode()));
 }
开发者ID:navassouza,项目名称:symfony,代码行数:24,代码来源:StubNumberFormatterTest.php

示例14: ut_main

function ut_main()
{
    $timezone = 'GMT+05:00';
    $locale_arr = array('en_US');
    $datetype_arr = array(IntlDateFormatter::FULL, IntlDateFormatter::LONG, IntlDateFormatter::MEDIUM);
    $res_str = '';
    $time_arr = array(0, -1200000, 1200000, 2200000000, -2200000000, 90099999, 3600, -3600);
    $localtime_arr1 = array('tm_sec' => 24, 'tm_min' => 3, 'tm_hour' => 19, 'tm_mday' => 3, 'tm_mon' => 3, 'tm_year' => 105);
    $localtime_arr2 = array('tm_sec' => 21, 'tm_min' => 5, 'tm_hour' => 7, 'tm_mday' => 13, 'tm_mon' => 7, 'tm_year' => 205);
    $localtime_arr3 = array('tm_sec' => 11, 'tm_min' => 13, 'tm_hour' => 0, 'tm_mday' => 17, 'tm_mon' => 11, 'tm_year' => -5);
    $localtime_arr = array($localtime_arr1, $localtime_arr2, $localtime_arr3);
    //Test format and parse with a timestamp : long
    foreach ($time_arr as $timestamp_entry) {
        $res_str .= "\n------------\n";
        $res_str .= "\nInput timestamp is : {$timestamp_entry}";
        $res_str .= "\n------------\n";
        foreach ($locale_arr as $locale_entry) {
            foreach ($datetype_arr as $datetype_entry) {
                $res_str .= "\nIntlDateFormatter locale= {$locale_entry} ,datetype = {$datetype_entry} ,timetype ={$datetype_entry} ";
                $fmt = ut_datefmt_create($locale_entry, $datetype_entry, $datetype_entry, $timezone);
                $formatted = ut_datefmt_format($fmt, $timestamp_entry);
                $res_str .= "\nFormatted timestamp is : {$formatted}";
                $parsed = ut_datefmt_parse($fmt, $formatted);
                if (intl_get_error_code() == U_ZERO_ERROR) {
                    $res_str .= "\nParsed timestamp is : {$parsed}";
                } else {
                    $res_str .= "\nError while parsing as: '" . intl_get_error_message() . "'";
                }
            }
        }
    }
    //Test format and parse with a localtime :array
    foreach ($localtime_arr as $localtime_entry) {
        $res_str .= "\n------------\n";
        $res_str .= "\nInput localtime is : ";
        foreach ($localtime_entry as $key => $value) {
            $res_str .= "{$key} : '{$value}' , ";
        }
        $res_str .= "\n------------\n";
        foreach ($locale_arr as $locale_entry) {
            foreach ($datetype_arr as $datetype_entry) {
                $res_str .= "\nIntlDateFormatter locale= {$locale_entry} ,datetype = {$datetype_entry} ,timetype ={$datetype_entry} ";
                $fmt = ut_datefmt_create($locale_entry, $datetype_entry, $datetype_entry, $timezone);
                $formatted1 = ut_datefmt_format($fmt, $localtime_entry);
                if (intl_get_error_code() == U_ZERO_ERROR) {
                    $res_str .= "\nFormatted localtime_array is : {$formatted1}";
                } else {
                    $res_str .= "\nError while formatting as: '" . intl_get_error_message() . "'";
                }
                //Parsing
                $parsed_arr = ut_datefmt_localtime($fmt, $formatted1);
                if ($parsed_arr) {
                    $res_str .= "\nParsed array is: ";
                    foreach ($parsed_arr as $key => $value) {
                        $res_str .= "{$key} : '{$value}' , ";
                    }
                }
                /*
                				else{
                				    //$res_str .= "No values found from LocaleTime parsing.";
                				    $res_str .= "\tError : '".intl_get_error_message()."'";
                				}
                */
            }
        }
    }
    return $res_str;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:68,代码来源:dateformat_format_parse.php

示例15: getIntlErrorCode

 protected function getIntlErrorCode()
 {
     return intl_get_error_code();
 }
开发者ID:Dren-x,项目名称:mobit,代码行数:4,代码来源:IntlDateFormatterTest.php


注:本文中的intl_get_error_code函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。