当前位置: 首页>>代码示例>>PHP>>正文


PHP DateTime\DateTime类代码示例

本文整理汇总了PHP中Magento\Framework\Stdlib\DateTime\DateTime的典型用法代码示例。如果您正苦于以下问题:PHP DateTime类的具体用法?PHP DateTime怎么用?PHP DateTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: doFormatObject

 /**
  * Implements what IntlDateFormatter::formatObject() is in PHP 5.5+
  *
  * @param \IntlCalendar|\DateTime $object
  * @param string|int|array|null $format
  * @param string|null $locale
  * @return string
  * @throws LocalizedException
  */
 protected function doFormatObject($object, $format = null, $locale = null)
 {
     $pattern = $dateFormat = $timeFormat = $calendar = null;
     if (is_array($format)) {
         list($dateFormat, $timeFormat) = $format;
     } elseif (is_numeric($format)) {
         $dateFormat = $format;
     } elseif (is_string($format) || null == $format) {
         $dateFormat = $timeFormat = \IntlDateFormatter::MEDIUM;
         $pattern = $format;
     } else {
         throw new LocalizedException(new Phrase('Format type is invalid'));
     }
     $timezone = $object->getTimezone();
     if ($object instanceof \IntlCalendar) {
         $timezone = $timezone->toDateTimeZone();
     }
     $timezone = $timezone->getName();
     if ($timezone === '+00:00') {
         $timezone = 'UTC';
     } elseif ($timezone[0] === '+' || $timezone[0] === '-') {
         // $timezone[0] is first symbol of string
         $timezone = 'GMT' . $timezone;
     }
     return (new \IntlDateFormatter($locale, $dateFormat, $timeFormat, $timezone, $calendar, $pattern))->format($object);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:35,代码来源:DateTimeFormatter.php

示例2: testGmtTimestamp

 /**
  * @test
  */
 public function testGmtTimestamp()
 {
     $timezone = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime\\TimezoneInterface')->getMock();
     $timezone->expects($this->any())->method('date')->willReturn(new \DateTime('2015-04-02 21:03:00'));
     /** @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface $timezone */
     $dateTime = new DateTime($timezone);
     $this->assertEquals(gmdate('U', strtotime('2015-04-02 21:03:00')), $dateTime->gmtTimestamp('2015-04-02 21:03:00'));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:11,代码来源:DateTimeTest.php

示例3: _beforeSave

 /**
  * Process testimonial data before saving
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if (!$object->getId() || !$object->getDate()) {
         $object->setDate($this->_date->gmtDate());
     }
     return parent::_beforeSave($object);
 }
开发者ID:swissup,项目名称:testimonials,代码行数:14,代码来源:Data.php

示例4: changeQueueStatusWithLocking

 /**
  * Update the status of a queue record and check to confirm the exclusive change
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return bool
  */
 public function changeQueueStatusWithLocking(AbstractModel $object)
 {
     /* @var $object \ClassyLlama\AvaTax\Model\Queue */
     $object->setUpdatedAt($this->dateTime->gmtDate());
     $data = $this->prepareDataForUpdate($object);
     $originalQueueStatus = $object->getOrigData(self::QUEUE_STATUS_FIELD_NAME);
     $originalUpdatedAt = $object->getOrigData(self::UPDATED_AT_FIELD_NAME);
     // A conditional update does a read lock on update so we use the condition on the old
     // queue status here to guarantee that nothing else has modified the status for processing
     $condition = array();
     // update only the queue record identified by Id
     $condition[] = $this->getConnection()->quoteInto($this->getIdFieldName() . '=?', $object->getId());
     // only update the record if it is still pending
     $condition[] = $this->getConnection()->quoteInto(self::QUEUE_STATUS_FIELD_NAME . '=?', $originalQueueStatus);
     // only update the record if nothing else has updated it
     if ($originalUpdatedAt === null) {
         $condition[] = self::UPDATED_AT_FIELD_NAME . ' IS NULL';
     } else {
         $condition[] = $this->getConnection()->quoteInto(self::UPDATED_AT_FIELD_NAME . '=?', $originalUpdatedAt);
     }
     // update the record and get the number of affected records
     $affectedRowCount = $this->getConnection()->update($this->getMainTable(), $data, $condition);
     $result = false;
     if ($affectedRowCount > 0) {
         $object->setHasDataChanges(false);
         $result = true;
     }
     return $result;
 }
开发者ID:classyllama,项目名称:ClassyLlama_AvaTax,代码行数:35,代码来源:Queue.php

示例5: filterExpiredSessions

 /**
  * Filter expired sessions
  *
  * @param int $sessionLifeTime
  * @return $this
  */
 public function filterExpiredSessions($sessionLifeTime)
 {
     $connection = $this->getConnection();
     $gmtTimestamp = $this->dateTime->gmtTimestamp();
     $this->addFieldToFilter('updated_at', ['gt' => $connection->formatDate($gmtTimestamp - $sessionLifeTime)]);
     return $this;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:13,代码来源:Collection.php

示例6: testGetGmtOffset

 public function testGetGmtOffset()
 {
     $this->assertSame(-28800, $this->dateTime->getGmtOffset('seconds'));
     $this->assertSame(-28800, $this->dateTime->getGmtOffset('seconds11'));
     $this->assertSame(-480, $this->dateTime->getGmtOffset('minutes'));
     $this->assertSame(-8, $this->dateTime->getGmtOffset('hours'));
 }
开发者ID:,项目名称:,代码行数:7,代码来源:

示例7: execute

 /**
  * Save action
  *
  * @return \Magento\Framework\Controller\ResultInterface
  */
 public function execute()
 {
     $post = $this->getRequest()->getPostValue();
     /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
     $resultRedirect = $this->resultRedirectFactory->create();
     if ($post) {
         $model = $this->_objectManager->create('OuterEdge\\Layout\\Model\\Groups');
         $data = $this->getRequest()->getParam('group');
         if (isset($data['group_id'])) {
             $model->load($data['group_id']);
         } else {
             $data['created_at'] = $this->datetime->date();
         }
         $model->setData($data);
         try {
             $model->save();
             $this->messageManager->addSuccess(__('The data has been saved.'));
             $this->_objectManager->get('Magento\\Backend\\Model\\Session')->setFormData(false);
             if ($this->getRequest()->getParam('back')) {
                 return $resultRedirect->setPath('*/*/edit', ['group_id' => $model->getId(), '_current' => true]);
             }
             return $resultRedirect->setPath('*/*/');
         } catch (\Magento\Framework\Exception\LocalizedException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (\RuntimeException $e) {
             $this->messageManager->addError($e->getMessage());
         } catch (\Exception $e) {
             $this->messageManager->addException($e, __('Something went wrong while saving the data.'));
         }
         $this->_getSession()->setFormData($data);
         return $resultRedirect->setPath('*/*/edit', ['group_id' => $this->getRequest()->getParam('group_record_id')]);
     }
     return $resultRedirect->setPath('*/*/');
 }
开发者ID:outeredge,项目名称:magento-layout-module,代码行数:39,代码来源:Save.php

示例8: _beforeSave

 /**
  * Process post data before saving
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if (!$this->isValidNewsblock($object)) {
         throw new \Magento\Framework\Exception\LocalizedException(__('Please fill out newsblock fields.'));
     }
     $object->setUpdateTime($this->_date->gmtDate());
     return parent::_beforeSave($object);
 }
开发者ID:Tossimo,项目名称:Newsblock,代码行数:15,代码来源:Newsblock.php

示例9: _beforeSave

 /**
  * Before saving the object, add the created or updated times
  *
  * @param \Magento\Framework\Model\AbstractModel $object
  * @return $this
  */
 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if ($object->isObjectNew() && !$object->hasCreationTime()) {
         $object->setCreationTime($this->_date->gmtDate());
     }
     $object->setUpdateTime($this->_date->gmtDate());
     return parent::_beforeSave($object);
 }
开发者ID:richdynamix,项目名称:personalised-products,代码行数:14,代码来源:Export.php

示例10: testFilterExpiredSessions

 /**
  * @return void
  */
 public function testFilterExpiredSessions()
 {
     $sessionLifeTime = '600';
     $timestamp = time();
     $this->dateTimeMock->expects($this->once())->method('gmtTimestamp')->willReturn($timestamp);
     $this->collectionMock->expects($this->once())->method('addFieldToFilter')->with('updated_at', ['gt' => $this->collectionMock->getConnection()->formatDate($timestamp - $sessionLifeTime)])->willReturnSelf();
     $this->assertEquals($this->collectionMock, $this->collectionMock->filterExpiredSessions($sessionLifeTime));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:11,代码来源:CollectionTest.php

示例11: testFilterByLifetime

 /**
  * @return void
  */
 public function testFilterByLifetime()
 {
     $lifetime = 600;
     $timestamp = time();
     $this->dateTimeMock->expects($this->once())->method('gmtTimestamp')->willReturn($timestamp);
     $this->collectionMock->expects($this->once())->method('addFieldToFilter')->with('created_at', ['gt' => $this->collectionMock->getConnection()->formatDate($timestamp - $lifetime)])->willReturnSelf();
     $this->assertEquals($this->collectionMock, $this->collectionMock->filterByLifetime($lifetime));
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:11,代码来源:CollectionTest.php

示例12: testSessionExpired

 /**
  * @param bool $expectedResult
  * @param string $sessionLifetime
  * @dataProvider dataProviderSessionLifetime
  */
 public function testSessionExpired($expectedResult, $sessionLifetime)
 {
     $timestamp = time();
     $this->securityConfigMock->expects($this->once())->method('getAdminSessionLifetime')->will($this->returnValue($sessionLifetime));
     $this->dateTimeMock->expects($this->once())->method('gmtTimestamp')->willReturn($timestamp);
     $this->model->setUpdatedAt(date("Y-m-d H:i:s", $timestamp - 1));
     $this->assertEquals($expectedResult, $this->model->isSessionExpired());
 }
开发者ID:rafaelstz,项目名称:magento2,代码行数:13,代码来源:AdminSessionInfoTest.php

示例13: _beforeSave

 protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
 {
     if (!$object->getId()) {
         $object->setCreatedAt($this->_date->gmtDate());
     }
     $object->setUpdatedAt($this->_date->gmtDate());
     return $this;
 }
开发者ID:pradeeprcs,项目名称:TestModule,代码行数:8,代码来源:Test.php

示例14: prepare

 /**
  * Prepare online visitors for collection
  *
  * @param \Magento\Log\Model\Visitor\Online $object
  * @return $this
  * @throws \Exception
  */
 public function prepare(\Magento\Log\Model\Visitor\Online $object)
 {
     if ($object->getUpdateFrequency() + $object->getPrepareAt() > time()) {
         return $this;
     }
     $readAdapter = $this->_getReadAdapter();
     $writeAdapter = $this->_getWriteAdapter();
     $writeAdapter->beginTransaction();
     try {
         $writeAdapter->delete($this->getMainTable());
         $visitors = array();
         $lastUrls = array();
         // retrieve online visitors general data
         $lastDate = $this->_date->gmtTimestamp() - $object->getOnlineInterval() * 60;
         $select = $readAdapter->select()->from($this->getTable('log_visitor'), array('visitor_id', 'first_visit_at', 'last_visit_at', 'last_url_id'))->where('last_visit_at >= ?', $readAdapter->formatDate($lastDate));
         $query = $readAdapter->query($select);
         while ($row = $query->fetch()) {
             $visitors[$row['visitor_id']] = $row;
             $lastUrls[$row['last_url_id']] = $row['visitor_id'];
             $visitors[$row['visitor_id']]['visitor_type'] = \Magento\Customer\Model\Visitor::VISITOR_TYPE_VISITOR;
             $visitors[$row['visitor_id']]['customer_id'] = null;
         }
         if (!$visitors) {
             $this->commit();
             return $this;
         }
         // retrieve visitor remote addr
         $select = $readAdapter->select()->from($this->getTable('log_visitor_info'), array('visitor_id', 'remote_addr'))->where('visitor_id IN(?)', array_keys($visitors));
         $query = $readAdapter->query($select);
         while ($row = $query->fetch()) {
             $visitors[$row['visitor_id']]['remote_addr'] = $row['remote_addr'];
         }
         // retrieve visitor last URLs
         $select = $readAdapter->select()->from($this->getTable('log_url_info'), array('url_id', 'url'))->where('url_id IN(?)', array_keys($lastUrls));
         $query = $readAdapter->query($select);
         while ($row = $query->fetch()) {
             $visitorId = $lastUrls[$row['url_id']];
             $visitors[$visitorId]['last_url'] = $row['url'];
         }
         // retrieve customers
         $select = $readAdapter->select()->from($this->getTable('log_customer'), array('visitor_id', 'customer_id'))->where('visitor_id IN(?)', array_keys($visitors));
         $query = $readAdapter->query($select);
         while ($row = $query->fetch()) {
             $visitors[$row['visitor_id']]['visitor_type'] = \Magento\Customer\Model\Visitor::VISITOR_TYPE_CUSTOMER;
             $visitors[$row['visitor_id']]['customer_id'] = $row['customer_id'];
         }
         foreach ($visitors as $visitorData) {
             unset($visitorData['last_url_id']);
             $writeAdapter->insertForce($this->getMainTable(), $visitorData);
         }
         $writeAdapter->commit();
     } catch (\Exception $e) {
         $writeAdapter->rollBack();
         throw $e;
     }
     $object->setPrepareAt();
     return $this;
 }
开发者ID:pavelnovitsky,项目名称:magento2,代码行数:65,代码来源:Online.php

示例15: deleteOldEntries

 /**
  * Delete old entries
  *
  * @param int $minutes
  * @return int
  */
 public function deleteOldEntries($minutes)
 {
     if ($minutes > 0) {
         $connection = $this->getConnection();
         return $connection->delete($this->getMainTable(), $connection->quoteInto('type = "' . \Magento\Integration\Model\Oauth\Token::TYPE_REQUEST . '" AND created_at <= ?', $this->_dateTime->formatDate($this->date->gmtTimestamp() - $minutes * 60)));
     } else {
         return 0;
     }
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:15,代码来源:Token.php


注:本文中的Magento\Framework\Stdlib\DateTime\DateTime类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。