public function testFormatWithLocalizedMonthReplacement() { // F - A full textual representation of a month, such as January or March $formatOption = 'F Y/m/d H:i:s'; $language = $this->getMockBuilder('\\Language')->disableOriginalConstructor()->getMock(); $language->expects($this->once())->method('getMonthName')->with($this->equalTo('12'))->will($this->returnValue('Foo')); $instance = new IntlTimeFormatter(DITime::doUnserialize('1/2000/12/12/1/1/20.200'), $language); $this->assertEquals('Foo 2000/12/12 01:01:20', $instance->format($formatOption)); }
/** * @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; }