Skip to content
Permalink
Browse files

Add an exception when datefmt_create fails.

Try to provide more useful feedback over method call on null.

Refs #12304
  • Loading branch information...
markstory committed Jul 3, 2018
1 parent d997562 commit 7a20e8b785d0d9388f76f3d34520702870ab0bdc
Showing with 9 additions and 1 deletion.
  1. +9 −1 src/I18n/DateFormatTrait.php
@@ -17,6 +17,7 @@
use Cake\Chronos\Date as ChronosDate;
use Cake\Chronos\MutableDate;
use IntlDateFormatter;
use RuntimeException;
/**
* Trait for date formatting methods shared by both Time & Date.
@@ -214,14 +215,21 @@ protected function _formatObject($date, $format, $locale)
} elseif ($timezone[0] === '+' || $timezone[0] === '-') {
$timezone = 'GMT' . $timezone;
}
static::$_formatters[$key] = datefmt_create(
$formatter = datefmt_create(
$locale,
$dateFormat,
$timeFormat,
$timezone,
$calendar,
$pattern
);
if (!$formatter) {
throw new RuntimeException(
'Your version of icu does not support creating a date formatter for ' .
"`$key`. You should try to upgrade libicu and the intl extension."
);
}
static::$_formatters[$key] = $formatter;
}
return static::$_formatters[$key]->format($date->format('U'));

0 comments on commit 7a20e8b

Please sign in to comment.
You can’t perform that action at this time.