/** * @dataProvider localizedFormatProvider */ public function testGetLocalizedFormat($serialization, $languageCode, $flag, $expected) { $instance = new IntlTimeFormatter(DITime::doUnserialize($serialization), Localizer::getInstance()->getLanguage($languageCode)); $this->assertEquals($expected, $instance->getLocalizedFormat($flag)); }
/** * @private * * @since 2.4 * * @param DITime|null $dataItem * * @return string */ public function getLocalizedFormat(DITime $dataItem = null) { if ($dataItem === null) { return ''; } if ($dataItem->getYear() < DITime::PREHISTORY) { return $this->getISO8601Date(); } $outputFormat = $this->dataValue->getOutputFormat(); $formatFlag = IntlTimeFormatter::LOCL_DEFAULT; if (strpos($outputFormat, 'TZ') !== false) { $formatFlag = IntlTimeFormatter::LOCL_TIMEZONE; $outputFormat = str_replace('#TZ', '', $outputFormat); } if (($language = Localizer::getInstance()->getLanguageCodeFrom($outputFormat)) === false) { $language = $this->dataValue->getOptionBy(DataValue::OPT_USER_LANGUAGE); } $language = Localizer::getInstance()->getLanguage($language); $intlTimeFormatter = new IntlTimeFormatter($dataItem, $language); // Avoid an exception on "DateTime::__construct(): Failed to parse time // string (2147483647-01-01 00:00:0.0000000) at position 17 (0): Double // time specification" for an annotation like [[Date::Jan 10000000000]] try { $localizedFormat = $intlTimeFormatter->getLocalizedFormat($formatFlag) . $this->hintCalendarModel($dataItem); } catch (\Exception $e) { $localizedFormat = $this->getISO8601Date(); } return $localizedFormat; }