コード例 #1
0
 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));
 }
コード例 #2
0
 /**
  * @since 2.4
  *
  * @param  DITime|null $dataItem
  *
  * @return string
  */
 public function getCaptionFromFreeFormat(DITime $dataItem = null)
 {
     $language = Localizer::getInstance()->getLanguage($this->dataValue->getOptionBy(DataValue::OPT_USER_LANGUAGE));
     // Prehistory dates are not supported when using this output format
     // Only match options encapsulated by [ ... ]
     if ($dataItem !== null && $dataItem->getYear() > DITime::PREHISTORY && preg_match("/\\[([^\\]]*)\\]/", $this->dataValue->getOutputFormat(), $matches)) {
         $intlTimeFormatter = new IntlTimeFormatter($dataItem, $language);
         if (($caption = $intlTimeFormatter->format($matches[1])) !== false) {
             if ($intlTimeFormatter->containsValidDateFormatRule($matches[1])) {
                 $caption .= $this->hintCalendarModel($dataItem);
             }
             return $caption;
         }
     }
     return $this->getISO8601Date();
 }