Commit cc4307d1 by Alexander Makarov

Better Formatter error handler

parent 4a543317
...@@ -131,7 +131,12 @@ class Formatter extends \yii\base\Formatter ...@@ -131,7 +131,12 @@ class Formatter extends \yii\base\Formatter
$formatter = new IntlDateFormatter($this->locale, $this->_dateFormats[$format], IntlDateFormatter::NONE); $formatter = new IntlDateFormatter($this->locale, $this->_dateFormats[$format], IntlDateFormatter::NONE);
} else { } else {
$formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE); $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE);
$formatter->setPattern($format); if ($formatter !== null) {
$formatter->setPattern($format);
}
}
if ($formatter === null) {
throw new InvalidConfigException(intl_get_error_message());
} }
return $formatter->format($value); return $formatter->format($value);
} }
...@@ -167,7 +172,12 @@ class Formatter extends \yii\base\Formatter ...@@ -167,7 +172,12 @@ class Formatter extends \yii\base\Formatter
$formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, $this->_dateFormats[$format]); $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, $this->_dateFormats[$format]);
} else { } else {
$formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE); $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE);
$formatter->setPattern($format); if ($formatter !== null) {
$formatter->setPattern($format);
}
}
if ($formatter === null) {
throw new InvalidConfigException(intl_get_error_message());
} }
return $formatter->format($value); return $formatter->format($value);
} }
...@@ -203,7 +213,12 @@ class Formatter extends \yii\base\Formatter ...@@ -203,7 +213,12 @@ class Formatter extends \yii\base\Formatter
$formatter = new IntlDateFormatter($this->locale, $this->_dateFormats[$format], $this->_dateFormats[$format]); $formatter = new IntlDateFormatter($this->locale, $this->_dateFormats[$format], $this->_dateFormats[$format]);
} else { } else {
$formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE); $formatter = new IntlDateFormatter($this->locale, IntlDateFormatter::NONE, IntlDateFormatter::NONE);
$formatter->setPattern($format); if ($formatter !== null) {
$formatter->setPattern($format);
}
}
if ($formatter === null) {
throw new InvalidConfigException(intl_get_error_message());
} }
return $formatter->format($value); return $formatter->format($value);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment