/**
  * @private
  *
  * Compute a string representation that largely follows the ISO8601 standard
  * of representing dates. Large year numbers may have more than 4 digits,
  * which is not strictly conforming to the standard. The date includes year,
  * month, and day regardless of the input precision, but will only include
  * time when specified.
  *
  * Conforming to the 2000 version of ISO8601, year 1 BC(E) is represented
  * as "0000", year 2 BC(E) as "-0001" and so on.
  *
  * @since 2.4
  *
  * @param DITime $dataItem
  * @param boolean $mindefault determining whether values below the
  * precision of our input should be completed with minimal or maximal
  * conceivable values
  *
  * @return string
  */
 public function getISO8601Date($mindefault = true)
 {
     $dataItem = $this->dataValue->getDataItemForCalendarModel(DITime::CM_GREGORIAN);
     $precision = $dataItem->getPrecision();
     $result = $dataItem->getYear() > 0 ? '' : '-';
     $result .= str_pad($dataItem->getYear(), 4, "0", STR_PAD_LEFT);
     $monthnum = $precision >= DITime::PREC_YM ? $dataItem->getMonth() : ($mindefault ? 1 : 12);
     $result .= '-' . str_pad($monthnum, 2, "0", STR_PAD_LEFT);
     $day = $dataItem->getDay();
     if (!$mindefault && $precision < DITime::PREC_YMD) {
         $day = DITime::getDayNumberForMonth($monthnum, $dataItem->getYear(), DITime::CM_GREGORIAN);
     }
     $result .= '-' . str_pad($day, 2, "0", STR_PAD_LEFT);
     if ($precision === DITime::PREC_YMDT) {
         $result .= 'T' . $this->getTimeString($mindefault ? '00:00:00' : '23:59:59');
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * Compute a string representation that largely follows the ISO8601
  * standard of representing dates. Large year numbers may have more
  * than 4 digits, which is not strictly conforming to the standard.
  * The date includes year, month, and day regardless of the input
  * precision, but will only include time when specified.
  *
  * Conforming to the 2000 version of ISO8601, year 1 BC(E) is
  * represented as "0000", year 2 BC(E) as "-0001" and so on.
  *
  * @param $mindefault boolean determining whether values below the
  * precision of our input should be completed with minimal or maximal
  * conceivable values
  * @return string
  */
 public function getISO8601Date($mindefault = true)
 {
     $result = $this->getYear() > 0 ? '' : '-';
     $monthnum = $this->getMonth(SMWDITime::CM_GREGORIAN, $mindefault ? 1 : 12);
     $result .= str_pad($this->getYear(), 4, "0", STR_PAD_LEFT) . '-' . str_pad($monthnum, 2, "0", STR_PAD_LEFT);
     if (!$mindefault && $this->m_dataitem->getPrecision() < SMWDITime::PREC_YMD) {
         $maxday = SMWDITime::getDayNumberForMonth($monthnum, $this->getYear(), SMWDITime::CM_GREGORIAN);
         $result .= '-' . str_pad($this->getDay(SMWDITime::CM_GREGORIAN, $maxday), 2, "0", STR_PAD_LEFT);
     } else {
         $result .= '-' . str_pad($this->getDay(), 2, "0", STR_PAD_LEFT);
     }
     if ($this->m_dataitem->getPrecision() == SMWDITime::PREC_YMDT) {
         $result .= 'T' . $this->getTimeString($mindefault ? '00:00:00' : '23:59:59');
     }
     return $result;
 }