/**
  * @since 2.4
  *
  * @param integer $formatFlag
  *
  * @return string|boolean
  */
 public function getLocalizedFormat($formatFlag = self::LOCL_DEFAULT)
 {
     $dateTime = $this->dataItem->asDateTime();
     $timezoneLiteral = '';
     if (!$dateTime) {
         return false;
     }
     if ($formatFlag === self::LOCL_TIMEZONE) {
         $timezoneLiteral = $this->getTimezoneLiteralWithModifiedDateTime($dateTime);
     }
     $extraneousLanguage = Localizer::getInstance()->getExtraneousLanguage($this->language);
     $precision = $this->dataItem->getPrecision();
     // Look for the Z precision which indicates the position of the TZ
     if ($precision === SMW_PREC_YMDT && $timezoneLiteral !== '') {
         $precision = SMW_PREC_YMDTZ;
     }
     $preferredDateFormatByPrecision = $extraneousLanguage->getPreferredDateFormatByPrecision($precision);
     // Mark the position since we cannot use DateTime::setTimezone in case
     // it is a military zone
     $preferredDateFormatByPrecision = str_replace('T', '**', $preferredDateFormatByPrecision);
     $dateString = $this->formatWithLocalizedTextReplacement($dateTime, $preferredDateFormatByPrecision);
     return str_replace('**', $timezoneLiteral, $dateString);
 }
Ejemplo n.º 2
0
 /**
  * Compute a suitable string to display the given date item.
  * @note MediaWiki's date functions are not applicable for the range of historic dates we support.
  *
  * @since 1.6
  *
  * @param SMWDITime $dataitem
  *
  * @return string
  * @todo Internationalize the CE and BCE strings.
  */
 public function getCaptionFromDataitem(SMWDITime $dataitem)
 {
     /**
      * @var SMWLanguage $smwgContLang
      */
     global $smwgContLang;
     if ($dataitem->getYear() > 0) {
         $cestring = '';
         $result = number_format($dataitem->getYear(), 0, '.', '') . ($cestring ? ' ' . $cestring : '');
     } else {
         $bcestring = 'BC';
         $result = number_format(-$dataitem->getYear(), 0, '.', '') . ($bcestring ? ' ' . $bcestring : '');
     }
     if ($dataitem->getPrecision() >= SMWDITime::PREC_YM) {
         $result = $smwgContLang->getMonthLabel($dataitem->getMonth()) . " " . $result;
     }
     if ($dataitem->getPrecision() >= SMWDITime::PREC_YMD) {
         $result = $dataitem->getDay() . " " . $result;
     }
     if ($dataitem->getPrecision() >= SMWDITime::PREC_YMDT) {
         $result .= " " . $this->getTimeString();
     }
     return $result;
 }
 private function parseToTimeValueForGregorianCalendarModel(DITime $dataItem)
 {
     if ($dataItem->getYear() > 0) {
         $xsdvalue = str_pad($dataItem->getYear(), 4, "0", STR_PAD_LEFT);
     } else {
         $xsdvalue = '-' . str_pad(1 - $dataItem->getYear(), 4, "0", STR_PAD_LEFT);
     }
     $xsdtype = 'http://www.w3.org/2001/XMLSchema#gYear';
     if ($dataItem->getPrecision() >= DITime::PREC_YM) {
         $xsdtype = 'http://www.w3.org/2001/XMLSchema#gYearMonth';
         $xsdvalue .= '-' . str_pad($dataItem->getMonth(), 2, "0", STR_PAD_LEFT);
         if ($dataItem->getPrecision() >= DITime::PREC_YMD) {
             $xsdtype = 'http://www.w3.org/2001/XMLSchema#date';
             $xsdvalue .= '-' . str_pad($dataItem->getDay(), 2, "0", STR_PAD_LEFT);
             if ($dataItem->getPrecision() == DITime::PREC_YMDT) {
                 $xsdtype = 'http://www.w3.org/2001/XMLSchema#dateTime';
                 $xsdvalue .= 'T' . sprintf("%02d", $dataItem->getHour()) . ':' . sprintf("%02d", $dataItem->getMinute()) . ':' . sprintf("%02d", $dataItem->getSecond());
             }
         }
     }
     $this->xsdValue = $xsdvalue .= 'Z';
     $this->xsdType = $xsdtype;
 }
Ejemplo n.º 4
0
 private function parseToTimeValueForGregorianCalendarModel(DITime $dataItem)
 {
     if ($dataItem->getYear() > 0) {
         $xsdvalue = str_pad($dataItem->getYear(), 4, "0", STR_PAD_LEFT);
     } else {
         $xsdvalue = '-' . str_pad(1 - $dataItem->getYear(), 4, "0", STR_PAD_LEFT);
     }
     $xsdtype = 'http://www.w3.org/2001/XMLSchema#gYear';
     if ($dataItem->getPrecision() >= DITime::PREC_YM) {
         $xsdtype = 'http://www.w3.org/2001/XMLSchema#gYearMonth';
         $xsdvalue .= '-' . str_pad($dataItem->getMonth(), 2, "0", STR_PAD_LEFT);
         if ($dataItem->getPrecision() >= DITime::PREC_YMD) {
             $xsdtype = 'http://www.w3.org/2001/XMLSchema#date';
             $xsdvalue .= '-' . str_pad($dataItem->getDay(), 2, "0", STR_PAD_LEFT);
             if ($dataItem->getPrecision() == DITime::PREC_YMDT) {
                 $xsdtype = 'http://www.w3.org/2001/XMLSchema#dateTime';
                 $xsdvalue .= 'T' . sprintf("%02d", $dataItem->getHour()) . ':' . sprintf("%02d", $dataItem->getMinute()) . ':' . sprintf("%02d", $dataItem->getSecond());
             }
             // https://www.w3.org/TR/2005/NOTE-timezone-20051013/
             // "Time zone identification in the date and time types relies
             // entirely on time zone offset from UTC."
             // Zone offset Z indicates UTC
             $xsdvalue .= 'Z';
         }
     }
     $this->xsdValue = $xsdvalue;
     $this->xsdType = $xsdtype;
 }
 /**
  * @private
  *
  * @todo Internationalize the CE and BCE strings.
  *
  * Compute a suitable string to display the given date item.
  *
  * @note MediaWiki's date functions are not applicable for the range of
  * historic dates we support.
  *
  * @since 2.4
  *
  * @param DITime $dataitem
  *
  * @return string
  */
 public function getCaptionFromDataItem(DITime $dataItem)
 {
     // If the language code is empty then the content language code is used
     $extraneousLanguage = Localizer::getInstance()->getExtraneousLanguage(Localizer::getInstance()->getContentLanguage());
     // https://en.wikipedia.org/wiki/Anno_Domini
     // "...placing the "AD" abbreviation before the year number ... BC is
     // placed after the year number (for example: AD 2016, but 68 BC)..."
     // Chicago Manual of Style 2010, pp. 476–7; Goldstein 2007, p. 6.
     if ($dataItem->getYear() > 0) {
         $cestring = $dataItem->getEra() > 0 ? 'AD' : '';
         $result = ($cestring ? $cestring . ' ' : '') . number_format($dataItem->getYear(), 0, '.', '');
     } else {
         $bcestring = 'BC';
         $result = number_format(-$dataItem->getYear(), 0, '.', '') . ($bcestring ? ' ' . $bcestring : '');
     }
     if ($dataItem->getPrecision() >= DITime::PREC_YM) {
         $result = $extraneousLanguage->getMonthLabel($dataItem->getMonth()) . " " . $result;
     }
     if ($dataItem->getPrecision() >= DITime::PREC_YMD) {
         $result = $dataItem->getDay() . " " . $result;
     }
     if ($dataItem->getPrecision() >= DITime::PREC_YMDT) {
         $result .= " " . $this->getTimeString();
     }
     $result .= $this->hintCalendarModel($dataItem);
     return $result;
 }