/**
  * @dataProvider longerThanOrEqualsProvider
  *
  * @param Duration $duration1
  * @param Duration $duration2
  * @param boolean $expected
  */
 public function testLongerThanOrEquals(Duration $duration1, Duration $duration2, $expected)
 {
     $this->assertSame($expected, $duration1->longerThanOrEquals($duration2));
 }
 /**
  * Subtract a duration to this one. If $duration is greather than or equal to
  * the current duration, a duration of 0 seconds is returned.
  * 
  * For instance P2S - P1S = P1S
  */
 public function sub(Duration $duration)
 {
     if ($duration->longerThanOrEquals($this) === true) {
         $this->setInterval(new DateInterval('PT0S'));
     } else {
         $refStrDate = '@0';
         $tz = new DateTimeZone(self::TIMEZONE);
         $d1 = new DateTime($refStrDate, $tz);
         $d2 = new DateTime($refStrDate, $tz);
         $d1->add(new DateInterval($this->__toString()));
         $d2->add(new DateInterval($duration->__toString()));
         $interval = $d1->diff($d2);
         $this->setInterval($interval);
     }
 }
 /**
  * Write a Duration in the current binary stream.
  * 
  * @param Duration $duration A Duration object.
  * @throws QtiBinaryStreamAccessException
  */
 public function writeDuration(Duration $duration)
 {
     try {
         $this->writeString($duration->__toString());
     } catch (BinaryStreamAccessException $e) {
         $msg = "An error occured while writing a duration.";
         throw new QtiBinaryStreamAccessException($msg, $this, QtiBinaryStreamAccessException::DURATION, $e);
     }
 }
 /**
  * Update the duration built-in variable. The update will only take
  * place if the current state of the item session is INTERACTING.
  * 
  */
 public function updateDuration()
 {
     // If the current state is INTERACTING update duration built-in variable.
     if ($this->getState() === AssessmentItemSessionState::INTERACTING) {
         $timeRef = $this->getTimeReference();
         $now = new DateTime('now', new DateTimeZone('UTC'));
         $data =& $this->getDataPlaceHolder();
         $diff = $timeRef->diff($now);
         $data['duration']->getValue()->add($diff);
         $this->setTimeReference($now);
         foreach ($this->onDurationUpdate as $callBack) {
             call_user_func_array($callBack, array($this, Duration::createFromDateInterval($diff)));
         }
     }
 }
Beispiel #5
0
 /**
  * Marshall a QTI duration datatype into its PCI JSON Representation.
  *
  * @param \qtism\common\datatypes\Duration $duration
  * @return array
  */
 protected function marshallDuration(Duration $duration)
 {
     return array('base' => array('duration' => $duration->__toString()));
 }