/** * Gets the formatter to use. * <p> * The formatter will be the most appropriate to use for the date and time style in the locale. * For example, some locales will use the month name while others will use the number. * * @param Locale $locale the locale to use, not null * @param Chronology $chrono the chronology to use, not null * @return DateTimeFormatter the formatter, not null * @throws IllegalArgumentException if the formatter cannot be found */ private function formatter(Locale $locale, Chronology $chrono) { $key = $chrono->getId() . '|' . $locale . '|' . $this->dateStyle . '|' . $this->timeStyle; $formatter = @self::$FORMATTER_CACHE[$key]; if ($formatter === null) { $pattern = DateTimeFormatterBuilder::getLocalizedDateTimePattern($this->dateStyle, $this->timeStyle, $chrono, $locale); $formatter = (new DateTimeFormatterBuilder())->appendPattern($pattern)->toFormatter2($locale); $old = self::$FORMATTER_CACHE[$key] = $formatter; if ($old !== null) { $formatter = $old; } } return $formatter; }
public function test_getLocalizedLocaleNPE() { TestHelper::assertNullException($this, function () { DateTimeFormatterBuilder::getLocalizedDateTimePattern(FormatStyle::SHORT(), FormatStyle::SHORT(), IsoChronology::INSTANCE(), null); }); }