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


PHP FormatConverter::convertDatePhpToIcu方法代码示例

本文整理汇总了PHP中yii\helpers\FormatConverter::convertDatePhpToIcu方法的典型用法代码示例。如果您正苦于以下问题:PHP FormatConverter::convertDatePhpToIcu方法的具体用法?PHP FormatConverter::convertDatePhpToIcu怎么用?PHP FormatConverter::convertDatePhpToIcu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在yii\helpers\FormatConverter的用法示例。


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

示例1: formatDateTimeValue

 private function formatDateTimeValue($value, $format, $type)
 {
     $timeZone = $this->timeZone;
     // avoid time zone conversion for date-only values
     if ($type === 'date') {
         list($timestamp, $hasTimeInfo) = $this->normalizeDatetimeValue($value, true);
         if (!$hasTimeInfo) {
             $timeZone = $this->defaultTimeZone;
         }
     } else {
         $timestamp = $this->normalizeDatetimeValue($value);
     }
     if ($timestamp === null) {
         return $this->nullDisplay;
     }
     // intl does not work with dates >=2038 or <=1901 on 32bit machines, fall back to PHP
     $year = $timestamp->format('Y');
     if ($this->_intlLoaded && !(PHP_INT_SIZE == 4 && ($year <= 1901 || $year >= 2038))) {
         if (strncmp($format, 'php:', 4) === 0) {
             $format = FormatConverter::convertDatePhpToIcu(substr($format, 4));
         }
         if (isset($this->_dateFormats[$format])) {
             if ($type === 'date') {
                 $formatter = new IntlDateFormatter($this->locale, $this->_dateFormats[$format], IntlDateFormatter::NONE, $timeZone);
             } elseif ($type === 'time') {
                 $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, $this->_dateFormats[$format], $timeZone);
             } else {
                 $formatter = new IntlDateFormatter($this->locale, $this->_dateFormats[$format], $this->_dateFormats[$format], $timeZone);
             }
         } else {
             $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE, $timeZone, null, $format);
         }
         if ($formatter === null) {
             throw new InvalidConfigException(intl_get_error_message());
         }
         // make IntlDateFormatter work with DateTimeImmutable
         if ($timestamp instanceof \DateTimeImmutable) {
             $timestamp = new DateTime($timestamp->format(DateTime::ISO8601), $timestamp->getTimezone());
         }
         return $formatter->format($timestamp);
     } else {
         if (strncmp($format, 'php:', 4) === 0) {
             $format = substr($format, 4);
         } else {
             $format = FormatConverter::convertDateIcuToPhp($format, $type, $this->locale);
         }
         if ($timeZone != null) {
             if ($timestamp instanceof \DateTimeImmutable) {
                 $timestamp = $timestamp->setTimezone(new DateTimeZone($timeZone));
             } else {
                 $timestamp->setTimezone(new DateTimeZone($timeZone));
             }
         }
         return $timestamp->format($format);
     }
 }
开发者ID:Mynameadmin,项目名称:Yii2-Learning-Source,代码行数:56,代码来源:ThaiYearFormatter.php

示例2: evaluateAttributes

 public function evaluateAttributes($event)
 {
     if (strncmp($this->sourceFormat, 'php:', 4) === 0) {
         $sourceFormat = FormatConverter::convertDatePhpToIcu(substr($this->sourceFormat, 4));
     } else {
         $sourceFormat = $this->sourceFormat;
     }
     $formatter = new \IntlDateFormatter(Yii::$app->formatter->locale, null, null, Yii::$app->formatter->timeZone, Yii::$app->formatter->calendar, $sourceFormat);
     foreach ($this->attributes as $attribute) {
         $value = $this->owner->{$attribute};
         if (empty($value)) {
             continue;
         }
         $this->owner->{$attribute} = Yii::$app->formatter->asDateTime($formatter->parse($value), $this->destinationFormat);
     }
 }
开发者ID:ejen,项目名称:yii2-datetime-behavior,代码行数:16,代码来源:DateTimeBehavior.php

示例3: init

 /**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     if (!isset($this->options['id'])) {
         $this->options['id'] = $this->getId();
         $this->name = $this->getId();
     }
     if (!$this->hasModel()) {
         throw new InvalidConfigException("DateRangePicker requires a model, check docs for usage.");
     }
     Html::addCssClass($this->options, ['date-range-picker', 'form-control']);
     if (!$this->dateFormat) {
         $this->dateFormat = Yii::$app->formatter->dateFormat;
     }
     if ($this->getDate('start') && $this->getDate('end')) {
         $this->clientOptions['startDate'] = new JsExpression('moment("' . $this->getDate('start') . '")');
         $this->clientOptions['endDate'] = new JsExpression('moment("' . $this->getDate('end') . '")');
     }
     $dateFormat = $this->dateFormat;
     if (strncmp($this->dateFormat, 'php:', 4) === 0) {
         $dateFormat = FormatConverter::convertDatePhpToIcu(substr($this->dateFormat, 4));
     }
     $this->clientOptions['locale'] = ['format' => MomentFormatConverter::convert($dateFormat)];
 }
开发者ID:webtoolsnz,项目名称:yii2-widgets,代码行数:26,代码来源:DateRangePicker.php

示例4: asFuzzyDate

 /**
  * @param $value array - a fuzzy date in array form (having keys 'y', 'm', and 'd').
  * @param null $format - see $fuzzyDateFormat; if null $fuzzyDateFormat is used
  * @return string - the formatted fuzzy date
  * @throws NotSupportedException
  */
 public function asFuzzyDate($value, $format = null)
 {
     $_dateFormats = ['short' => IntlDateFormatter::SHORT, 'medium' => IntlDateFormatter::MEDIUM, 'long' => IntlDateFormatter::LONG, 'full' => IntlDateFormatter::FULL];
     if ($value === null) {
         return $this->nullDisplay;
     }
     if (!is_array($value)) {
         throw new InvalidParamException('Formatting fuzzy date failed.');
     }
     if (!extension_loaded('intl')) {
         // can't use $this->_intlLoaded (private)
         throw new NotSupportedException('Extension \'Intl\' not loaded');
     }
     if (!$format) {
         $format = $this->fuzzyDateFormat;
     }
     $granularity = 'full';
     if (!isset($value['d']) || empty($value['d'])) {
         $granularity = isset($value['m']) && !empty($value['m']) ? 'month' : 'year';
     }
     $dt = new DateTime();
     $tokens = null;
     switch ($granularity) {
         case 'month':
             $dt->setDate($value['y'], $value['m'], 1);
             $tokens = 'cDdEeFWw';
             // ICU-tokens having to do with day
             break;
         case 'year':
             $dt->setDate($value['y'], 1, 1);
             $tokens = 'cDdEeFLMWw';
             // ICU-tokens having to do with day or month
             break;
         default:
             // 'full', finest granularity, use full pattern
             $dt->setDate($value['y'], $value['m'], $value['d']);
             break;
     }
     $formatter = null;
     if (is_array($format)) {
         $pattern = $format[$granularity];
     } else {
         if (isset($_dateFormats[$format])) {
             $formatter = new IntlDateFormatter($this->locale, $_dateFormats[$format], IntlDateFormatter::NONE);
             $format = $formatter->getPattern();
         } else {
             if (strncmp($format, 'php:', 4) === 0) {
                 $format = FormatConverter::convertDatePhpToIcu(substr($format, 4));
             }
         }
         if ($tokens) {
             // use PCRE_UTF8 modifier ('u') for regular expressions
             $pattern = preg_replace("/'[^']+'\\s?[{$tokens}]+\\S?\\s?|(?:('[^']+')|[{$tokens}]+\\S?\\s?)/u", '$1', $format);
             // remove tokens, possibly
             // with prepended quoted string, possibly with appended non-space and space, unless in single quoted string
             $pattern = preg_replace('/^(\'[^\']*\'\\s*)+|(\\s*\'[^\']*\')+$|\\W$/u', '', $pattern);
             // remove (possibly multiple) quoted strings at begin or end, non-word character from end
         } else {
             $pattern = $format;
         }
     }
     if (!$formatter) {
         $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE);
     }
     // New in 1.0.1 : fall back to PHP if 32 bits and 'extreme' date
     if (PHP_INT_SIZE > 4 || $value['y'] > 1901 && $value['y'] < 2038) {
         $formatter->setPattern($pattern);
         return $formatter->format($dt);
     } else {
         return $dt->format(FormatConverter::convertDateIcuToPhp($pattern));
     }
 }
开发者ID:sjaakp,项目名称:yii2-fuzzydate,代码行数:78,代码来源:Formatter.php

示例5: formatDateTimeValue

 /**
  * @param integer|string|DateTime $value the value to be formatted. The following
  * types of value are supported:
  *
  * - an integer representing a UNIX timestamp
  * - a string that can be [parsed to create a DateTime object](http://php.net/manual/en/datetime.formats.php).
  *   The timestamp is assumed to be in UTC unless a timezone is explicitly given.
  * - a PHP [DateTime](http://php.net/manual/en/class.datetime.php) object
  *
  * @param string $format the format used to convert the value into a date string.
  * @param string $type 'date', 'time', or 'datetime'.
  * @throws InvalidConfigException if the date format is invalid.
  * @return string the formatted result.
  */
 private function formatDateTimeValue($value, $format, $type)
 {
     $timestamp = $this->normalizeDatetimeValue($value);
     if ($timestamp === null) {
         return $this->nullDisplay;
     }
     if ($this->_intlLoaded) {
         if (strncmp($format, 'php:', 4) === 0) {
             $format = FormatConverter::convertDatePhpToIcu(substr($format, 4));
         }
         if (isset($this->_dateFormats[$format])) {
             if ($type === 'date') {
                 $formatter = new IntlDateFormatter($this->locale, $this->_dateFormats[$format], IntlDateFormatter::NONE, $this->timeZone);
             } elseif ($type === 'time') {
                 $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, $this->_dateFormats[$format], $this->timeZone);
             } else {
                 $formatter = new IntlDateFormatter($this->locale, $this->_dateFormats[$format], $this->_dateFormats[$format], $this->timeZone);
             }
         } else {
             $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE, $this->timeZone, null, $format);
         }
         if ($formatter === null) {
             throw new InvalidConfigException(intl_get_error_message());
         }
         return $formatter->format($timestamp);
     } else {
         if (strncmp($format, 'php:', 4) === 0) {
             $format = substr($format, 4);
         } else {
             $format = FormatConverter::convertDateIcuToPhp($format, $type, $this->locale);
         }
         if ($this->timeZone != null) {
             $timestamp->setTimezone(new DateTimeZone($this->timeZone));
         }
         return $timestamp->format($format);
     }
 }
开发者ID:phaniapsr,项目名称:yiicomm,代码行数:51,代码来源:Formatter.php

示例6: parseDateTimeValue

 private function parseDateTimeValue($value, $format, $type)
 {
     if ($value === null || $value == '') {
         return null;
     }
     $timeZone = $this->formatter->timeZone;
     if ($this->_intlLoaded) {
         if (strncmp($format, 'php:', 4) === 0) {
             $format = FormatConverter::convertDatePhpToIcu(substr($format, 4));
         }
         if (isset($this->_dateFormats[$format])) {
             if ($type === 'date') {
                 $formatter = new IntlDateFormatter($this->formatter->locale, $this->_dateFormats[$format], IntlDateFormatter::NONE, $timeZone);
             } elseif ($type === 'time') {
                 $formatter = new IntlDateFormatter($this->formatter->locale, IntlDateFormatter::NONE, $this->_dateFormats[$format], $timeZone);
             } else {
                 $formatter = new IntlDateFormatter($this->formatter->locale, $this->_dateFormats[$format], $this->_dateFormats[$format], $timeZone);
             }
         } else {
             $formatter = new IntlDateFormatter($this->formatter->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE, $timeZone, null, $format);
         }
         if ($formatter === null) {
             throw new InvalidConfigException(intl_get_error_message());
         }
         if (($result = $formatter->parse($value)) === false) {
             throw new InvalidParamException('Parsing date/time value failed: ' . $formatter->getErrorCode() . ' ' . $formatter->getErrorMessage());
         }
         return $result;
     } else {
         throw new InvalidConfigException('Parse as Date/Time is only supported when PHP intl extension is installed.');
     }
 }
开发者ID:RangelReale,项目名称:yii2-dataformat,代码行数:32,代码来源:DataFormat.php

示例7: normalizeIcuFormat

 /**
  * @param string|array $format
  * @param Formatter $formatter
  * @throws InvalidParamException
  * @return array|string
  */
 public static function normalizeIcuFormat($format, $formatter)
 {
     if (is_string($format)) {
         switch ($format) {
             case 'date':
                 $format = $formatter->dateFormat;
                 if (strncmp($format, 'php:', 4) === 0) {
                     $format = FormatConverter::convertDatePhpToIcu(substr($format, 4));
                 }
                 return ['date', $format];
             case 'time':
                 $format = $formatter->timeFormat;
                 if (strncmp($format, 'php:', 4) === 0) {
                     $format = FormatConverter::convertDatePhpToIcu(substr($format, 4));
                 }
                 return ['time', $format];
             case 'datetime':
                 $format = $formatter->datetimeFormat;
                 if (strncmp($format, 'php:', 4) === 0) {
                     $format = FormatConverter::convertDatePhpToIcu(substr($format, 4));
                 }
                 return ['datetime', $format];
             default:
                 throw new InvalidParamException('$format has incorrect value');
         }
     } elseif (is_array($format) && count($format) < 2) {
         throw new InvalidParamException('When $format is presented in array form, it must have at least two elements');
     }
     return $format;
 }
开发者ID:omnilight,项目名称:yii2-datetime,代码行数:36,代码来源:DateTimeBehavior.php


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