toDateTime() public method

Returns a DateTime object representing this date
public toDateTime ( ) : DateTime
return DateTime
Exemplo n.º 1
0
 /**
  * @param $attribute
  * @param \MongoDate|string|int $oldValue
  * @param \MongoDate|string|int $newValue
  * @return array|bool
  */
 private function getLogRow($attribute, $oldValue, $newValue)
 {
     $row = ['date' => new \MongoDate(), 'user' => \Yii::$app->user->identity['fullName']];
     switch ($attribute) {
         case 'date':
             $row['action'] = "Изменилась дата с " . \Yii::$app->formatter->asDate($oldValue->toDateTime()) . " на " . \Yii::$app->formatter->asDate($newValue->toDateTime());
             return $row;
         case 'beginTime':
             $row['action'] = "Изменилось время начала с " . MinuteFormatter::asString($oldValue) . " на " . MinuteFormatter::asString($newValue);
             return $row;
         case 'endTime':
             $row['action'] = "Изменилось время окончания с " . MinuteFormatter::asString($oldValue) . " на " . MinuteFormatter::asString($newValue);
             return $row;
         case 'participantsId':
             $action = '';
             foreach ($newValue as $item) {
                 $index = array_search($item, $oldValue);
                 if ($index !== false) {
                     unset($oldValue[$index]);
                 } else {
                     $action .= "Участник '" . Participant::findOne(['_id' => $item])->shortName . "' был добавлен\n";
                 }
             }
             foreach ($oldValue as $item) {
                 $action .= "Участник '" . Participant::findOne(['_id' => $item])->shortName . "' был удалён\n";
             }
             $row['action'] = $action;
             return $row;
         default:
             return false;
     }
 }
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $this->formatter = $this->getHelper('formatter');
     $text = "Initializing all dates to 'public'...";
     $this->writeOutput($output, $text, 'comment');
     $this->dm = $this->getContainer()->get('doctrine_mongodb')->getManager();
     $this->mmobjRepo = $this->dm->getRepository('PumukitSchemaBundle:MultimediaObject');
     $numberMmobjs = $this->mmobjRepo->createQueryBuilder()->count()->getQuery()->execute();
     $allMmobjs = $this->mmobjRepo->createQueryBuilder()->getQuery()->execute();
     $todayDate = new \MongoDate();
     $text = sprintf('There are %s objects. Initializing to %s', $numberMmobjs, $todayDate->toDateTime()->format('d/m/Y'));
     $this->writeOutput($output, $text, 'comment');
     $count = 0;
     $time_started = microtime(true);
     foreach ($allMmobjs as $mmobj) {
         ++$count;
         $mmobj->setPublicDate($todayDate);
         $this->dm->persist($mmobj);
         if ($count % 300 == 0) {
             $this->dm->flush();
             $this->dm->clear();
             $this->showProgressEstimation($output, $count, $numberMmobjs, $time_started);
         }
     }
     $this->showProgressEstimation($output, $count, $numberMmobjs, $time_started);
     $text = 'Script FINISHED.';
     $this->writeOutput($output, $text, 'comment');
 }
 /**
  * @depends testCreate
  */
 public function testConvertToBson(\MongoDate $date)
 {
     $this->skipTestUnless($date instanceof TypeInterface);
     $dateTime = $date->toDateTime();
     $bsonDate = $date->toBSONType();
     $this->assertInstanceOf('MongoDB\\BSON\\UTCDateTime', $bsonDate);
     $this->assertSame('1234567890123', (string) $bsonDate);
     $bsonDateTime = $bsonDate->toDateTime();
     // Compare timestamps to avoid issues with DateTime
     $timestamp = $dateTime->format('U') . '.' . $dateTime->format('U');
     $bsonTimestamp = $bsonDateTime->format('U') . '.' . $bsonDateTime->format('U');
     $this->assertSame((double) $timestamp, (double) $bsonTimestamp);
 }