Example #1
0
 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 \'г\'.'));
 }
Example #2
0
 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);
 }
 /**
  * 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());
 }
Example #4
0
 /**
  * @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 [];
     }
 }
Example #5
0
 /**
  * @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()]);
 }
 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);
 }
 /**
  * @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);
 }
 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);
 }
Example #9
0
 /**
  * Renders the widget.
  */
 public function run()
 {
     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 ($language != 'en-US') {
         $view = $this->getView();
         $bundle = DatePickerLanguageAsset::register($view);
         if ($bundle->autoGenerate) {
             $view->registerJsFile($bundle->baseUrl . "/ui/i18n/datepicker-{$language}.js", ['depends' => [JuiAsset::className()]]);
         }
         $options = Json::encode($this->clientOptions);
         $view->registerJs("\$('#{$containerID}').datepicker(\$.extend({}, \$.datepicker.regional['{$language}'], {$options}));");
     } else {
         $this->registerClientOptions('datepicker', $containerID);
     }
     $this->registerClientEvents('datepicker', $containerID);
     JuiAsset::register($this->getView());
 }
Example #10
0
    public static function getTypeList()
    {
        $dateFormat = Yii::$app->formatter->dateFormat;
        if (strncmp(Yii::$app->formatter->dateFormat, 'php:', 4) === 0) {
            $dateFormat = FormatConverter::convertDatePhpToJui(substr($dateFormat, 4));
        } else {
            $dateFormat = FormatConverter::convertDateIcuToJui($dateFormat, 'date', Yii::$app->language);
        }
        return [static::TEXT_TYPE => ['comparisons' => static::getTextTypeComparisons(), 'formatter' => 'raw', 'options' => ['inputType' => 'text']], static::NUMERIC_TYPE => ['comparisons' => static::getNumericTypeComparisons(), 'formatter' => 'integer', 'options' => ['inputType' => 'text']], static::DATE_TYPE => ['comparisons' => static::getDateTypeComparisons(), 'formatter' => ['date', 'php:Y-m-d'], 'options' => ['inputType' => 'date', 'language' => Yii::$app->language, 'renderScript' => new JsExpression('function(parameter) {
                        var self = this;
                        parameter.row.find(".datepicker").each(function(){
                            var datePicker = $(this);
                            var parameterValue = datePicker.prev(".parameter-value");

                            function parseISO8601(dateStringInRange) {
                                var isoExp = /^\\s*(\\d{4})-(\\d\\d)-(\\d\\d)\\s*$/,
                                    date = new Date(NaN), month,
                                    parts = isoExp.exec(dateStringInRange);

                                if(parts) {
                                  month = +parts[2];
                                  date.setFullYear(parts[1], month - 1, parts[3]);
                                  if(month != date.getMonth() + 1) {
                                    date.setTime(NaN);
                                  }
                                }
                                return date;
                              }

                            var dt = parseISO8601(datePicker.val());
                            dt.setTime( dt.getTime() + dt.getTimezoneOffset()*60*1000 );
                            var options = $.extend(
                                {
                                    "defaultValue": dt,
                                    "altField": parameterValue,
                                    "onClose": function(dateText, inst) {
                                        if (dateText == "") {
                                            var altField = $(inst.settings["altField"]);
                                            if (altField.length) {
                                                altField.val(dateText);
                                            }
                                        }
                                        parameterValue.trigger("change");
                                    }
                                },
                                self.clientOptions
                            );

                            if (self.language !== "en-US") {
                                options = $.extend(options, $.datepicker.regional[self.language]);
                            }

                            datePicker.datepicker(options).datepicker("setDate", dt);
                        });
                    }'), 'postRenderScript' => new JsExpression('function(parameter) {
                        parameter.row.find(".datepicker").each(function(){
                            var datePicker = $(this);
                            var parameterValue = datePicker.prev(".parameter-value");
                            parameterValue.trigger("change");
                        });
                    }'), 'clientOptions' => ['dateFormat' => $dateFormat, 'altFormat' => 'yy-mm-dd']]], static::LIST_TYPE => ['comparisons' => static::getListTypeComparisons(), 'formatter' => 'raw', 'options' => ['inputType' => 'select', 'renderScript' => new JsExpression('function(parameter) {
                        parameter.row.find(".parameter-value").select2({ "width": "100%" });
                    }'), 'valueOptions' => ['' => '']]], static::BOOL_TYPE => ['comparisons' => static::getBooleanTypeComparison(), 'formatter' => 'integer', 'options' => ['inputType' => 'select', 'valueOptions' => ['' => '', '0' => Yii::t('modules/parameters', 'False'), '1' => Yii::t('modules/parameters', 'True')]]]];
    }
 public function testEscapedIcuToJui()
 {
     $this->assertEquals('l, F j, Y \\a\\t g:i:s a T', FormatConverter::convertDateIcuToPhp('EEEE, MMMM d, y \'at\' h:mm:ss a zzzz'));
     $this->assertEquals('\'o\'\'clock\'', FormatConverter::convertDateIcuToJui('\'o\'\'clock\''));
 }