本文整理汇总了PHP中Magento\Framework\Stdlib\DateTime\DateTime类的典型用法代码示例。如果您正苦于以下问题:PHP DateTime类的具体用法?PHP DateTime怎么用?PHP DateTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DateTime类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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: generatePool
/**
* Generate Coupons Pool
*
* @throws \Magento\Framework\Exception\LocalizedException
* @return $this
*/
public function generatePool()
{
$this->generatedCount = 0;
$size = $this->getQty();
$maxAttempts = $this->getMaxAttempts() ? $this->getMaxAttempts() : self::MAX_GENERATE_ATTEMPTS;
$this->increaseLength();
/** @var $coupon \Magento\SalesRule\Model\Coupon */
$coupon = $this->couponFactory->create();
$nowTimestamp = $this->dateTime->formatDate($this->date->gmtTimestamp());
for ($i = 0; $i < $size; $i++) {
$attempt = 0;
do {
if ($attempt >= $maxAttempts) {
throw new \Magento\Framework\Exception\LocalizedException(__('We cannot create the requested Coupon Qty. Please check your settings and try again.'));
}
$code = $this->generateCode();
++$attempt;
} while ($this->getResource()->exists($code));
$expirationDate = $this->getToDate();
if ($expirationDate instanceof \DateTime) {
$expirationDate = $expirationDate->format('Y-m-d H:i:s');
}
$coupon->setId(null)->setRuleId($this->getRuleId())->setUsageLimit($this->getUsesPerCoupon())->setUsagePerCustomer($this->getUsesPerCustomer())->setExpirationDate($expirationDate)->setCreatedAt($nowTimestamp)->setType(\Magento\SalesRule\Helper\Coupon::COUPON_TYPE_SPECIFIC_AUTOGENERATED)->setCode($code)->save();
$this->generatedCount += 1;
}
return $this;
}
开发者ID:nja78,项目名称:magento2,代码行数:33,代码来源:Massgenerator.php
示例4: _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
示例5: 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
示例6: 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
示例7: 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,代码来源:
示例8: 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
示例9: _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
示例10: _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
示例11: 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
示例12: 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
示例13: 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
示例14: _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
示例15: 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
示例16: 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
示例17: massAction
/**
* Print credit memos for selected orders
*
* @param AbstractCollection $collection
* @return ResponseInterface|ResultInterface
*/
protected function massAction(AbstractCollection $collection)
{
$creditmemoCollection = $this->collectionFactory->create()->setOrderFilter(['in' => $collection->getAllIds()]);
if (!$creditmemoCollection->getSize()) {
$this->messageManager->addError(__('There are no printable documents related to selected orders.'));
return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl());
}
return $this->fileFactory->create(sprintf('creditmemo%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), $this->pdfCreditmemo->getPdf($creditmemoCollection->getItems())->render(), DirectoryList::VAR_DIR, 'application/pdf');
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:15,代码来源:Pdfcreditmemos.php
示例18: testSendPerSubscriberZeroSize
public function testSendPerSubscriberZeroSize()
{
$this->queue->setQueueStatus(1);
$this->queue->setQueueStartAt(1);
$this->subscribersCollection->expects($this->once())->method('getQueueJoinedFlag')->willReturn(false);
$this->subscribersCollection->expects($this->once())->method('useQueue')->with($this->queue)->willReturnSelf();
$this->subscribersCollection->expects($this->once())->method('getSize')->willReturn(0);
$this->date->expects($this->once())->method('gmtDate')->willReturn('any_date');
$this->assertEquals($this->queue, $this->queue->sendPerSubscriber());
}
开发者ID:Doability,项目名称:magento2dev,代码行数:10,代码来源:QueueTest.php
示例19: _initSelect
/**
* Init collection select
*
* @return $this
*/
protected function _initSelect()
{
parent::_initSelect();
$connection = $this->getConnection();
$lastDate = $this->date->gmtTimestamp() - $this->visitorModel->getOnlineInterval() * self::SECONDS_IN_MINUTE;
$this->getSelect()->joinLeft(['customer' => $this->getTable('customer_entity')], 'customer.entity_id = main_table.customer_id', ['email', 'firstname', 'lastname'])->where('main_table.last_visit_at >= ?', $connection->formatDate($lastDate));
$expression = $connection->getCheckSql('main_table.customer_id IS NOT NULL AND main_table.customer_id != 0', $connection->quote(Visitor::VISITOR_TYPE_CUSTOMER), $connection->quote(Visitor::VISITOR_TYPE_VISITOR));
$this->getSelect()->columns(['visitor_type' => $expression]);
return $this;
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:Collection.php
示例20: validateConsumer
/**
* {@inheritdoc}
*/
public function validateConsumer($consumer)
{
// Must use consumer within expiration period.
$consumerTS = strtotime($consumer->getCreatedAt());
$expiry = $this->_dataHelper->getConsumerExpirationPeriod();
if ($this->_date->timestamp() - $consumerTS > $expiry) {
throw new \Magento\Framework\Oauth\Exception('Consumer key has expired');
}
return true;
}
开发者ID:Atlis,项目名称:docker-magento2,代码行数:13,代码来源:Provider.php
注:本文中的Magento\Framework\Stdlib\DateTime\DateTime类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论