php yii-helpers-FormatConverter类(方法)实例源码

下面列出了php yii-helpers-FormatConverter 类(方法)源码代码实例,从而了解它的用法。

作者:omniligh    项目:yii2-bootstrap-datepicke   
public function run()
 {
     echo $this->renderWidget() . "\n";
     if (is_string($this->noConflict)) {
         /** @var AssetBundle $asset */
         $asset = $this->noConflict;
         $asset::register($this->view);
     }
     $asset = DatePickerAsset::register($this->view);
     $containerID = $this->options['id'];
     $language = $this->language ? $this->language : Yii::$app->language;
     $this->view->registerJsFile($asset->baseUrl . '/locales/bootstrap-datepicker.' . $language . '.min.js', ['depends' => ['yii\\web\\JqueryAsset', 'omnilight\\assets\\DatePickerAsset']]);
     if (strncmp($this->dateFormat, 'php:', 4) === 0) {
         $format = substr($this->dateFormat, 4);
     } else {
         $format = FormatConverter::convertDateIcuToPhp($this->dateFormat, 'datetime', $language);
     }
     $this->clientOptions['format'] = $this->convertDateFormat($format);
     $this->clientOptions['language'] = $language;
     if ($this->noConflict) {
         $this->registerNoConflict();
         $this->registerClientOptions('datepickerNoConflict', $containerID);
     } else {
         $this->registerClientOptions('datepicker', $containerID);
     }
 }

作者:how    项目:yii   
public function testIntlUtf8Ru()
 {
     $this->assertEquals('d M Y \\г.', FormatConverter::convertDateIcuToPhp('dd MMM y \'г\'.', 'date', 'ru-RU'));
     $this->assertEquals('dd M yy \'г\'.', FormatConverter::convertDateIcuToJui('dd MMM y \'г\'.', 'date', 'ru-RU'));
     $formatter = new Formatter(['locale' => 'ru-RU']);
     $this->assertEquals('24 авг 2014 г.', $formatter->asDate('2014-8-24', 'dd MMM y \'г\'.'));
 }

作者:mdmsof    项目:yii2-format-converte   
/**
  * @inheritdoc
  */
 public function init()
 {
     if ($this->logicalFormat === null) {
         $format = $this->type . 'Format';
         $pattern = Yii::$app->formatter->{$format};
     } else {
         $pattern = $this->logicalFormat;
     }
     if (substr($pattern, 0, 4) === 'php:') {
         $this->_phpLogicalFormat = substr($pattern, 4);
     } else {
         $this->_phpLogicalFormat = FormatConverter::convertDateIcuToPhp($pattern, $this->type);
     }
     if ($this->physicalFormat === null) {
         $driverName = Yii::$app->db->driverName;
         if (isset(static::$dbDatetimeFormat[$driverName])) {
             $pattern = static::$dbDatetimeFormat[$driverName][$this->type];
         } else {
             $pattern = static::$dbDatetimeFormat['default'][$this->type];
         }
     } else {
         $pattern = $this->physicalFormat;
     }
     if (substr($pattern, 0, 4) === 'php:') {
         $this->_phpPhysicalFormat = substr($pattern, 4);
     } else {
         $this->_phpPhysicalFormat = FormatConverter::convertDateIcuToPhp($pattern, $this->type);
     }
     parent::init();
 }

作者:ahb36    项目:kalpo   
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;
     }
     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 $this->dateTime->date($format, $timestamp->getTimestamp());
 }

作者:andreosof    项目:andreocm   
public function run()
 {
     echo $this->renderWidget() . "\n";
     $view = $this->getView();
     $bundle = Asset::register($view);
     $containerID = $this->inline ? $this->containerOptions['id'] : $this->options['id'];
     $language = $this->language ? $this->language : \Yii::$app->language;
     if (strncmp($this->dateFormat, 'php:', 4) === 0) {
         $this->clientOptions['format'] = FormatConverter::convertDatePhpToJui(substr($this->dateFormat, 4), 'date', $language);
     } else {
         $this->clientOptions['format'] = FormatConverter::convertDateIcuToJui($this->dateFormat, 'date', $language);
     }
     $this->clientOptions['format'] = 'yyyy-mm-dd';
     if ($language != 'en-US') {
         if ($bundle->autoGenerate) {
             $fallbackLanguage = substr($language, 0, 2);
             if ($fallbackLanguage !== $language && !file_exists(\Yii::getAlias($bundle->sourcePath . "/locales/bootstrap-datepicker.{$language}.js"))) {
                 $language = $fallbackLanguage;
             }
             //               $view->registerJsFile($bundle->baseUrl . "/locales/bootstrap-datepicker.$language.js");
         }
         $options = Json::encode($this->clientOptions);
         $view->registerJs("\$('#{$containerID}').datepicker(\$.extend({}, {$options}));");
         //            $view->registerJs("$('#{$containerID}').datepicker($.extend({}, $.datepicker.regional['{$language}'], $options));");
     } else {
         $this->registerClientOptions('datepicker', $containerID);
     }
     //        $this->registerClientEvents('datepicker', $containerID);
 }

作者:maddoge    项目:yii2-cor   
public function init()
 {
     parent::init();
     if (!$this->_localFormatPhp) {
         $this->_localFormatPhp = FormatConverter::convertDateIcuToPhp($this->localFormat[1], $this->localFormat[0]);
     }
 }

作者:sallon8    项目:yii2-jui-timepicke   
/**
  * Renders the widget.
  */
 public function run()
 {
     $picker = $this->timeOnly ? 'timepicker' : 'datetimepicker';
     echo $this->renderWidget() . "\n";
     $containerID = $this->inline ? $this->containerOptions['id'] : $this->options['id'];
     $language = $this->language ? $this->language : Yii::$app->language;
     if (strncmp($this->dateFormat, 'php:', 4) === 0) {
         $this->clientOptions['dateFormat'] = FormatConverter::convertDatePhpToJui(substr($this->dateFormat, 4), 'date', $language);
     } else {
         $this->clientOptions['dateFormat'] = FormatConverter::convertDateIcuToJui($this->dateFormat, 'date', $language);
     }
     if ($this->timeFormat) {
         $this->clientOptions['timeFormat'] = $this->timeFormat;
     }
     if ($language != 'en-US' && $language != 'en') {
         $view = $this->getView();
         $bundle = DateTimePickerLanguageAsset::register($view);
         if ($bundle->autoGenerate) {
             $fallbackLanguage = substr($language, 0, 2);
             if ($fallbackLanguage !== $language && !file_exists(Yii::getAlias($bundle->sourcePath . "/dist/i18n/jquery-ui-timepicker-{$language}.js"))) {
                 $language = $fallbackLanguage;
             }
             $view->registerJsFile($bundle->baseUrl . "/dist/i18n/jquery-ui-timepicker-{$language}.js", ['depends' => [DateTimePickerAsset::className()]]);
         }
         $options = Json::encode($this->clientOptions);
         $view->registerJs("\$('#{$containerID}').{$picker}(\$.extend({}, \$.timepicker.regional['{$language}'], {$options}));");
     } else {
         $this->registerClientOptions($picker, $containerID);
     }
     $this->registerClientEvents($picker, $containerID);
     DateTimePickerAsset::register($this->getView());
 }

作者:roman444u    项目:yii2-datetim   
/**
  * @param string $value
  */
 public function setValue($value)
 {
     $this->_value = $value;
     $normalizedFormat = DateTimeBehavior::normalizeIcuFormat($this->targetFormat, $this->behavior->formatter);
     $phpFormat = FormatConverter::convertDateIcuToPhp($normalizedFormat[1], $normalizedFormat[0], \Yii::$app->language);
     $dateTime = date_create_from_format($phpFormat, $value);
     $this->behavior->owner->{$this->originalAttribute} = $this->behavior->formatter->format($dateTime, $this->originalFormat);
 }

作者:bupy    项目:yii2-date-range-picke   
/**
  * Converting the date format from PHP DateTime (or ICU format) to Moment.js DateTime format.
  * @param string $format the PHP date format string
  * @return string
  * @see http://php.net/manual/en/function.date.php
  * @see http://momentjs.com/docs/#/parsing/string-format/
  */
 protected function convertDateFormat($format)
 {
     if (strncmp($format, 'php:', 4) === 0) {
         $format = substr($format, 4);
     } else {
         $format = FormatConverter::convertDateIcuToPhp($format);
     }
     return strtr($format, ['s' => 'ss', 'i' => 'mm', 'g' => 'h', 'h' => 'hh', 'G' => 'H', 'H' => 'HH', 'w' => 'e', 'W' => 'E', 'j' => 'D', 'd' => 'DD', 'D' => 'DDD', 'l' => 'DDDD', 'n' => 'M', 'm' => 'MM', 'M' => 'MMM', 'F' => 'MMMM', 'y' => 'YY', 'Y' => 'YYYY', 'U' => 'X']);
 }

作者:maddoge    项目:yii2-cor   
/**
  * @param DateTimeAttribute $attribute
  * @param string $datePickerClass
  * @return array
  */
 public static function jui($attribute, $datePickerClass = 'yii\\jui\\DatePicker')
 {
     $format = $attribute->localFormat;
     switch ($datePickerClass) {
         case 'yii\\jui\\DatePicker':
             return ['language' => \Yii::$app->language, 'clientOptions' => ['dateFormat' => FormatConverter::convertDateIcuToJui($format[1], $format[0])]];
         default:
             return [];
     }
 }

作者:maddoge    项目:yii2-datetimepicke   
public function init()
 {
     parent::init();
     if ($this->timeZoneConvert === null) {
         $this->timeZoneConvert = !($this->originalFormat != 'U' && $this->localFormat[0] == 'date');
     }
     if (!$this->_localFormatPhp) {
         $this->_localFormatPhp = FormatConverter::convertDateIcuToPhp($this->localFormat[1], $this->localFormat[0]);
     }
 }

作者:modernkerne    项目:yii2-skeleto   
/**
  * convert current yii date format to timestamp
  * @param string $date current date in Yii date format
  * @return bool|int
  */
 public static function date2timestamp($date)
 {
     $format = Yii::$app->formatter->dateFormat;
     if (strncmp($format, 'php:', 4) === 0) {
         $format = substr($format, 4);
     } else {
         $format = FormatConverter::convertDateIcuToPhp($format);
     }
     $d = DateTime::createFromFormat($format, $date);
     if ($d) {
         return $d->getTimestamp();
     }
     return false;
 }

作者:webtoolsn    项目:yii2-widget   
/**
  * @throws \yii\base\InvalidConfigException
  */
 public function init()
 {
     parent::init();
     Html::addCssClass($this->options, ['progressive-datepicker', 'form-control']);
     if (!$this->dateFormat) {
         $this->dateFormat = Yii::$app->formatter->dateFormat;
     }
     if (strncmp($this->dateFormat, 'php:', 4) === 0) {
         $this->clientOptions['dateFormat'] = FormatConverter::convertDatePhpToJui(substr($this->dateFormat, 4));
     } else {
         $this->clientOptions['dateFormat'] = FormatConverter::convertDateIcuToJui($this->dateFormat);
     }
     $this->options = array_merge($this->options, ['type' => 'date', 'value' => $this->getDate(), 'formattedValue' => $this->getFormattedDate()]);
 }

作者:michael-vostriko    项目:books-tes   
public function registerScript()
 {
     $language = $this->language ? $this->language : Yii::$app->language;
     if (strncmp($this->saveDateFormat, 'php:', 4) === 0) {
         $saveDateFormatJs = FormatConverter::convertDatePhpToJui(substr($this->saveDateFormat, 4));
     } else {
         $saveDateFormatJs = FormatConverter::convertDateIcuToJui($this->saveDateFormat, 'date', $language);
     }
     $this->saveDateFormatJs = $saveDateFormatJs;
     $containerID = $this->inline ? $this->containerOptions['id'] : $this->options['id'];
     $hiddenInputID = $this->options['savedValueInputID'];
     $script = "\r\n            \$('#{$containerID}').change(function() {\r\n                var savedValue = \$.datepicker.formatDate('{$saveDateFormatJs}', \$(this).datepicker('getDate'));\r\n                \$('#{$hiddenInputID}').val(savedValue).trigger('change');\r\n            });\r\n        ";
     $view = $this->getView();
     $view->registerJs($script);
 }

作者:eje    项目:yii2-datetime-behavio   
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);
     }
 }

作者:omniligh    项目:yii2-datetim   
/**
  * @param Model $model
  * @param $attribute
  * @param array $options
  * @param string $datePickerClass
  * @return array
  */
 public static function get(Model $model, $attribute, $options = [], $datePickerClass = 'yii\\jui\\DatePicker')
 {
     try {
         $attribute = self::findAttribute($model, $attribute);
         $format = DateTimeBehavior::normalizeIcuFormat($attribute->targetFormat, $attribute->behavior->formatter);
         switch ($datePickerClass) {
             case 'yii\\jui\\DatePicker':
                 $defaults = ['language' => \Yii::$app->language, 'clientOptions' => ['dateFormat' => 'php:' . FormatConverter::convertDateIcuToJui($format[1], $format[0])]];
                 break;
             case 'omnilight\\widgets\\DatePicker':
                 $defaults = ['language' => \Yii::$app->language, 'dateFormat' => 'php:' . FormatConverter::convertDateIcuToPhp($format[1], $format[0])];
                 break;
             default:
                 return $options;
         }
     } catch (InvalidParamException $e) {
         $defaults = [];
     }
     return ArrayHelper::merge($defaults, $options);
 }

作者:roman444u    项目:yii2-datetim   
/**
  * @param Model $model
  * @param string $attribute
  * @param array $options
  * @param string $datePickerClass
  * @return array
  */
 public static function get(Model $model, $attribute, $options = [], $datePickerClass = DateRangePicker::class)
 {
     $behavior = self::findBehavior($model, $attribute);
     $formatAttribute = null;
     try {
         $formatAttribute = self::findAttribute($model, $behavior->startAttribute);
         $formatAttribute = self::findAttribute($model, $behavior->endAttribute);
     } catch (InvalidParamException $e) {
     }
     $defaults = [];
     switch ($datePickerClass) {
         case DateRangePicker::class:
             $defaults = ['separator' => $behavior->separator];
             if ($formatAttribute) {
                 $format = DateTimeBehavior::normalizeIcuFormat($formatAttribute->targetFormat, $formatAttribute->behavior->formatter);
                 $defaults['dateFormat'] = 'php:' . FormatConverter::convertDateIcuToPhp($format[1], $format[0]);
             }
             break;
     }
     return ArrayHelper::merge($defaults, $options);
 }

作者:meysamp    项目:yii2-jtimepicke   
public function run()
 {
     $view = $this->getView();
     echo $this->renderWidget() . "\n";
     $containerID = $this->inline ? $this->containerOptions['id'] : $this->options['id'];
     $language = $this->language ? $this->language : Yii::$app->language;
     if (strncmp($this->dateFormat, 'php:', 4) === 0) {
         $this->clientOptions['dateFormat'] = FormatConverter::convertDatePhpToJui(substr($this->dateFormat, 4));
     } else {
         $this->clientOptions['dateFormat'] = FormatConverter::convertDateIcuToJui($this->dateFormat, 'date', $language);
     }
     if ($language !== 'en-US') {
         $options = Json::htmlEncode($this->clientOptions);
         $language = Html::encode($language);
         $view->registerJs("\$('#{$containerID}').datetimepicker(\$.extend({}, \$.datepicker.regional['{$language}'], {$options}));");
     } else {
         $this->registerClientOptions('datetimepicker', $containerID);
     }
     $this->registerClientEvents('datetimepicker', $containerID);
     JTimePickerAsset::register($view);
 }

作者:webtoolsn    项目:yii2-widget   
/**
  * @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)];
 }

作者:Mynameadmi    项目:Yii2-Learning-Sourc   
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);
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号