/**
  * @inheritdoc
  */
 public static function convertDatePhpOrIcuToJui($pattern, $type = 'date', $locale = null)
 {
     if ($type == 'time') {
         if (strncmp($pattern, 'php:', 4) === 0) {
             return static::convertTimePhpToJui(substr($pattern, 4));
         } else {
             return static::convertTimePhpToJui(static::convertDateIcuToPhp($pattern, $type, $locale));
         }
     } else {
         return parent::convertDatePhpOrIcuToJui($pattern, $type, $locale);
     }
 }
 /**
  * @inheritdoc
  */
 public function init()
 {
     parent::init();
     if (is_null($this->dateFormat)) {
         $this->dateFormat = Yii::$app->getFormatter()->dateFormat;
         if (is_null($this->dateFormat)) {
             $this->dateFormat = 'medium';
         }
     }
     if (is_null($this->altDateFormat)) {
         $this->altDateFormat = 'yyyy-MM-dd';
     }
     Html::addCssClass($this->options, 'form-control');
     $this->altOptions['id'] = $this->options['id'] . '-alt';
     $this->clientOptions = array_merge(array_diff_assoc(['numberOfMonths' => $this->numberOfMonths, 'showButtonPanel' => $this->showButtonPanel], get_class_vars(__CLASS__)), $this->clientOptions, ['dateFormat' => FormatConverter::convertDatePhpOrIcuToJui($this->dateFormat), 'altField' => '#' . $this->altOptions['id'], 'altFormat' => FormatConverter::convertDatePhpOrIcuToJui($this->altDateFormat)]);
     if (array_key_exists('readonly', $this->options) && $this->options['readonly']) {
         if (!array_key_exists('beforeShow', $this->clientOptions)) {
             $this->clientOptions['beforeShow'] = new JsExpression('function (input, inst) { return false; }');
         }
     }
 }
 /**
  * @param string $phpFormat
  * @param string $icuFormat
  * @param string $juiFormat
  * @dataProvider formatsDataProvider
  */
 public function testConvertDatePhpOrIcuToJui($phpFormat, $icuFormat, $juiFormat)
 {
     $this->assertEquals($juiFormat, FormatConverter::convertDatePhpOrIcuToJui($phpFormat));
     $this->assertEquals($juiFormat, FormatConverter::convertDatePhpOrIcuToJui($icuFormat));
 }
    /**
     * @param int $mode
     * @param string $value
     * @dataProvider modeValueDataProvider
     */
    public function testWidgetClientOptions($mode, $value)
    {
        $actual = $this->getActual($mode, $value, ['clientOptions' => ['defaultDate' => -1, 'duration' => 'slow']]);
        list($id, $name) = $this->getIdName($mode);
        if (is_int($value) || is_string($value) && strlen($value) || $value instanceof DateTime || $value instanceof DateTimeInterface) {
            $formatter = Yii::$app->getFormatter();
            $encodedValueAttr = ' value="' . Html::encode($formatter->asDate($value)) . '"';
            $encodedAltValueAttr = ' value="' . Html::encode($formatter->asDate($value, 'yyyy-MM-dd')) . '"';
        } elseif (!is_null($value)) {
            $encodedValueAttr = ' value="' . Html::encode($value) . '"';
            $encodedAltValueAttr = ' value="' . Html::encode($value) . '"';
        } else {
            $encodedValueAttr = '';
            $encodedAltValueAttr = '';
        }
        $expectedHtml = <<<EXPECTED_HTML
<input type="text" id="{$id}" class="form-control"{$encodedValueAttr}><input type="hidden" id="{$id}-alt" name="{$name}"{$encodedAltValueAttr}>
EXPECTED_HTML;
        $dateFormat = str_replace('\'', '\\u0027', FormatConverter::convertDateIcuToJui('medium'));
        $expectedJs = <<<EXPECTED_JS
jQuery('#{$id}').datepicker({"defaultDate":-1,"duration":"slow","dateFormat":"{$dateFormat}","altField":"#{$id}-alt","altFormat":"yy-mm-dd"});
EXPECTED_JS;
        $this->checkExpected($mode, $actual, $expectedHtml, $expectedJs);
    }