/**
  * @see ValueFormatter::format
  *
  * Generates HTML representing the details of a TimeValue,
  * as an itemized list.
  *
  * @param TimeValue $value
  *
  * @throws InvalidArgumentException
  * @return string HTML
  */
 public function format($value)
 {
     if (!$value instanceof TimeValue) {
         throw new InvalidArgumentException('Data value type mismatch. Expected a TimeValue.');
     }
     $timeHtml = $this->getTimestampHtml($value->getTime());
     $timeZone = $value->getTimezone();
     $timeZoneHtml = is_int($timeZone) ? $this->getTimeZoneHtml($timeZone) : htmlspecialchars($timeZone);
     $calendarHtml = $this->getCalendarModelHtml($value->getCalendarModel());
     $precision = $value->getPrecision();
     $before = $value->getBefore();
     $after = $value->getAfter();
     if (is_int($precision) && is_int($before) && is_int($after)) {
         $precisionHtml = $this->getAmountAndPrecisionHtml($precision);
         $beforeHtml = $this->getAmountAndPrecisionHtml($precision, $before);
         $afterHtml = $this->getAmountAndPrecisionHtml($precision, $after);
     } else {
         $precisionHtml = htmlspecialchars($precision);
         $beforeHtml = htmlspecialchars($value->getBefore());
         $afterHtml = htmlspecialchars($value->getAfter());
     }
     $html = '';
     $html .= Html::rawElement('h4', array('class' => 'wb-details wb-time-details wb-time-rendered'), $this->timeFormatter->format($value));
     $html .= Html::openElement('table', array('class' => 'wb-details wb-time-details'));
     $html .= $this->getFieldHtml('isotime', $timeHtml);
     $html .= $this->getFieldHtml('timezone', $timeZoneHtml);
     $html .= $this->getFieldHtml('calendar', $calendarHtml);
     $html .= $this->getFieldHtml('precision', $precisionHtml);
     $html .= $this->getFieldHtml('before', $beforeHtml);
     $html .= $this->getFieldHtml('after', $afterHtml);
     $html .= Html::closeElement('table');
     return $html;
 }
Exemplo n.º 2
0
 /**
  * This returns a Unix timestamp from a TimeValue similar to PHP's mk_time() (or strtotime()),
  * but with no range limitations. Data type is float because PHP's 32 bit integer would
  * clip in the year 2038.
  *
  * @param TimeValue $timeValue
  *
  * @return float seconds since 1970-01-01T00:00:00Z
  */
 public function getTimestamp(TimeValue $timeValue)
 {
     return $this->getSecondsSinceUnixEpoch($timeValue->getTime(), $timeValue->getTimezone());
 }
Exemplo n.º 3
0
 /**
  * @dataProvider instanceProvider
  */
 public function testGetTimezone(TimeValue $time, array $arguments)
 {
     $this->assertEquals($arguments[1], $time->getTimezone());
 }