private function convertToUtcDate($date = '')
 {
     // will be in current TIME_ZONE
     $dateTime = new DateTime($date);
     $dateTime->setTimezone(new \DateTimeZone('UTC'));
     return $dateTime->format(\DateTime::ISO8601);
 }
Example #2
0
 /**
  * Returns date formatted according to given format.
  *
  * @param string $format
  * @return string
  */
 public function format($format)
 {
     $format = str_replace('u', sprintf('%06d', $this->microseconds), $format);
     return parent::format($format);
 }
Example #3
0
 /**
  * @covers oat\dtms\DateTime::format
  */
 public function testFormat()
 {
     $dt = new DateTime('2015-08-08 10:10:10.123456');
     $this->assertSame('08.08.2015 10:10:10.123456', $dt->format('d.m.Y H:i:s.u'));
     $this->assertSame('08.08.2015 10:10:10', $dt->format('d.m.Y H:i:s'));
     $this->assertSame('1439028610.123456', $dt->format('U.u'));
 }
 /**
  * @param AssessmentItemRef $itemRef
  *
  * @return DateTime
  */
 public function getItemStartTime($itemRef)
 {
     $itemResults = array();
     $itemStartTime = null;
     $ssid = $this->getTestSession()->getSessionId();
     $resultServer = \taoResultServer_models_classes_ResultServerStateFull::singleton();
     $collection = $resultServer->getVariables("{$ssid}.{$itemRef->getIdentifier()}.{$this->getTestSession()->getCurrentAssessmentItemRefOccurence()}");
     foreach ($collection as $vars) {
         foreach ($vars as $var) {
             if ($var->variable instanceof taoResultServer_models_classes_TraceVariable && $var->variable->getIdentifier() === 'ITEM_START_TIME_SERVER') {
                 $itemResults[] = $var->variable->getValue();
             }
         }
     }
     $itemResults = array_map(function ($ts) {
         $itemStart = new DateTime('now', new DateTimeZone('UTC'));
         $itemStart->setTimestamp($ts);
         return $itemStart;
     }, $itemResults);
     if (!empty($itemResults)) {
         $itemStartTime = min($itemResults);
     }
     return $itemStartTime;
 }