/**
  * Helper function - creates an object of type SMWTimeValue based
  * on a "Julian day" integer
  */
 protected static function jdToTimeValue($jd)
 {
     $timeDataItem = SMWDITime::newFromJD($jd, SMWDITime::CM_GREGORIAN, SMWDITime::PREC_YMDT);
     $timeValue = new SMWTimeValue('_dat');
     $timeValue->setDataItem($timeDataItem);
     return $timeValue;
 }
 /**
  * @dataProvider jdProvider
  */
 public function testNewFromJD($jd, $expected)
 {
     $this->assertEquals(DITime::doUnserialize($expected), DITime::newFromJD($jd));
 }
 /**
  * Initialise data from the provided intermediate results after
  * parsing, assuming that a conventional date notation is used.
  * If errors occur, error messages are added to the objects list of
  * errors, and false is returned. Otherwise, true is returned.
  * @param $datecomponents array of strings that might belong to the specification of a date
  * @param $calendarmodesl string if model was set in input, otherwise false
  * @param $era string '+' or '-' if provided, otherwise false
  * @param $hours integer value between 0 and 24
  * @param $minutes integer value between 0 and 59
  * @param $seconds integer value between 0 and 59, or false if not given
  * @param $timeoffset double value for time offset (e.g. 3.5), or false if not given
  * @return boolean stating if successful
  */
 protected function setDateFromParsedValues($datecomponents, $calendarmodel, $era, $hours, $minutes, $seconds, $timeoffset)
 {
     $date = false;
     if (!$this->interpretDateComponents($datecomponents, $date)) {
         return false;
     }
     // Handle BC: the year is negative.
     if ($era == '-' && $date['y'] > 0) {
         // see class documentation on BC, "year 0", and ISO conformance ...
         $date['y'] = -$date['y'];
     }
     // Old Style is a special case of Julian calendar model where the change of the year was 25 March:
     if ($calendarmodel == 'OS' && ($date['m'] < 3 || $date['m'] == 3 && $date['d'] < 25)) {
         $date['y']++;
     }
     $calmod = $this->getCalendarModel($calendarmodel, $date['y'], $date['m'], $date['d']);
     try {
         $this->m_dataitem = new SMWDITime($calmod, $date['y'], $date['m'], $date['d'], $hours, $minutes, $seconds, $this->m_typeid);
     } catch (SMWDataItemException $e) {
         $this->addError(wfMessage('smw_nodatetime', $this->m_wikivalue)->inContentLanguage()->text());
         return false;
     }
     // Having more than years or specifying a calendar model does
     // not make sense for prehistoric dates, and our calendar
     // conversion would not be reliable if JD numbers get too huge:
     if ($date['y'] <= self::PREHISTORY && ($this->m_dataitem->getPrecision() > SMWDITime::PREC_Y || $calendarmodel !== false)) {
         $this->addError(wfMessage('smw_nodatetime', $this->m_wikivalue)->inContentLanguage()->text());
         return false;
     }
     if ($timeoffset != 0) {
         $newjd = $this->m_dataitem->getJD() - $timeoffset / 24;
         try {
             $this->m_dataitem = SMWDITime::newFromJD($newjd, $calmod, $this->m_dataitem->getPrecision(), $this->m_typeid);
         } catch (SMWDataItemException $e) {
             $this->addError(wfMessage('smw_nodatetime', $this->m_wikivalue)->inContentLanguage()->text());
             return false;
         }
     }
     return true;
 }