本文整理汇总了PHP中Magento\Framework\Stdlib\DateTime类的典型用法代码示例。如果您正苦于以下问题:PHP DateTime类的具体用法?PHP DateTime怎么用?PHP DateTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DateTime类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: processAuthenticationFailure
/**
* {@inheritdoc}
*/
public function processAuthenticationFailure($customerId)
{
$now = new \DateTime();
$lockThreshold = $this->getLockThreshold();
$maxFailures = $this->getMaxFailures();
$customerSecure = $this->customerRegistry->retrieveSecureData($customerId);
if (!($lockThreshold && $maxFailures)) {
return false;
}
$failuresNum = (int) $customerSecure->getFailuresNum() + 1;
$firstFailureDate = $customerSecure->getFirstFailure();
if ($firstFailureDate) {
$firstFailureDate = new \DateTime($firstFailureDate);
}
$lockThreshInterval = new \DateInterval('PT' . $lockThreshold . 'S');
// set first failure date when this is first failure or last first failure expired
if (1 === $failuresNum || !$firstFailureDate || $now->diff($firstFailureDate) > $lockThreshInterval) {
$customerSecure->setFirstFailure($this->dateTime->formatDate($now));
$failuresNum = 1;
// otherwise lock customer
} elseif ($failuresNum >= $maxFailures) {
$customerSecure->setLockExpires($this->dateTime->formatDate($now->add($lockThreshInterval)));
}
$customerSecure->setFailuresNum($failuresNum);
$this->customerRepository->save($this->customerRepository->getById($customerId));
}
开发者ID:rafaelstz,项目名称:magento2,代码行数:29,代码来源:Authentication.php
示例2: _beforeSave
/**
* Perform actions before object save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if ($date = $object->getDateFrom()) {
$object->setDateFrom($this->dateTime->formatDate($date));
} else {
$object->setDateFrom(null);
}
if ($date = $object->getDateTo()) {
$object->setDateTo($this->dateTime->formatDate($date));
} else {
$object->setDateTo(null);
}
if (!is_null($object->getDateFrom()) && !is_null($object->getDateTo()) && (new \DateTime($object->getDateFrom()))->getTimestamp() > (new \DateTime($object->getDateTo()))->getTimestamp()) {
throw new \Magento\Framework\Exception\LocalizedException(__('The start date can\'t follow the end date.'));
}
$check = $this->_checkIntersection($object->getStoreId(), $object->getDateFrom(), $object->getDateTo(), $object->getId());
if ($check) {
throw new \Magento\Framework\Exception\LocalizedException(__('The date range for this design change overlaps another design change for the specified store.'));
}
if ($object->getDateFrom() === null) {
$object->setDateFrom(new \Zend_Db_Expr('null'));
}
if ($object->getDateTo() === null) {
$object->setDateTo(new \Zend_Db_Expr('null'));
}
parent::_beforeSave($object);
}
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:34,代码来源:Design.php
示例3: addCreatedAtBeforeFilter
/**
* Filter collection by created at date older than specified seconds before now
*
* @param int $secondsBeforeNow
* @return $this
*/
public function addCreatedAtBeforeFilter($secondsBeforeNow)
{
$datetime = new \DateTime('now', new \DateTimeZone('UTC'));
$storeInterval = new \DateInterval('PT' . $secondsBeforeNow . 'S');
$datetime->sub($storeInterval);
$formattedDate = $this->dateTime->formatDate($datetime->getTimestamp());
$this->addFieldToFilter(Log::CREATED_AT_FIELD_NAME, ['lt' => $formattedDate]);
return $this;
}
开发者ID:classyllama,项目名称:ClassyLlama_AvaTax,代码行数:15,代码来源:Collection.php
示例4: addDateFilter
/**
* Add date filter to collection
*
* @param null|int|string|\DateTime $date
* @return $this
*/
public function addDateFilter($date = null)
{
if ($date === null) {
$date = $this->dateTime->formatDate(true);
} else {
$date = $this->dateTime->formatDate($date);
}
$this->addFieldToFilter('date_from', ['lteq' => $date]);
$this->addFieldToFilter('date_to', ['gteq' => $date]);
return $this;
}
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:17,代码来源:Collection.php
示例5: setUp
/**
* Setup
*
* @return void
*/
public function setUp()
{
$this->config = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Config')->disableOriginalConstructor()->setMethods(['isNewRelicEnabled'])->getMock();
$this->collect = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\Module\\Collect')->disableOriginalConstructor()->setMethods(['getModuleData'])->getMock();
$this->systemFactory = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\SystemFactory')->disableOriginalConstructor()->setMethods(['create'])->getMock();
$this->systemModel = $this->getMockBuilder('Magento\\NewRelicReporting\\Model\\System')->disableOriginalConstructor()->getMock();
$this->jsonEncoder = $this->getMockBuilder('Magento\\Framework\\Json\\EncoderInterface')->getMock();
$this->dateTime = $this->getMockBuilder('Magento\\Framework\\Stdlib\\DateTime')->disableOriginalConstructor()->setMethods(['formatDate'])->getMock();
$this->systemFactory->expects($this->any())->method('create')->willReturn($this->systemModel);
$this->jsonEncoder->expects($this->any())->method('encode')->willReturn('json_string');
$this->dateTime->expects($this->any())->method('formatDate')->willReturn('1970-01-01 00:00:00');
$this->model = new ReportModulesInfo($this->config, $this->collect, $this->systemFactory, $this->jsonEncoder, $this->dateTime);
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:18,代码来源:ReportModulesInfoTest.php
示例6: _beforeSave
/**
* {@inheritdoc}
*
* @param \Magento\Framework\Model\AbstractModel $change
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $change)
{
if (!$change->getChangeTime()) {
$change->setChangeTime($this->dateTime->formatDate(true));
}
return $this;
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:13,代码来源:Change.php
示例7: _beforeSave
/**
* Perform actions before object save
*
* @param \Magento\Framework\Model\AbstractModel $object
* @return $this
* @throws \Magento\Framework\Model\Exception
*/
public function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if ($date = $object->getDateFrom()) {
$object->setDateFrom($this->dateTime->formatDate($date));
} else {
$object->setDateFrom(null);
}
if ($date = $object->getDateTo()) {
$object->setDateTo($this->dateTime->formatDate($date));
} else {
$object->setDateTo(null);
}
if (!is_null($object->getDateFrom()) && !is_null($object->getDateTo()) && $this->dateTime->toTimestamp($object->getDateFrom()) > $this->dateTime->toTimestamp($object->getDateTo())) {
throw new \Magento\Framework\Model\Exception(__('Start date cannot be greater than end date.'));
}
$check = $this->_checkIntersection($object->getStoreId(), $object->getDateFrom(), $object->getDateTo(), $object->getId());
if ($check) {
throw new \Magento\Framework\Model\Exception(__('Your design change for the specified store intersects with another one, please specify another date range.'));
}
if ($object->getDateFrom() === null) {
$object->setDateFrom(new \Zend_Db_Expr('null'));
}
if ($object->getDateTo() === null) {
$object->setDateTo(new \Zend_Db_Expr('null'));
}
parent::_beforeSave($object);
}
开发者ID:aiesh,项目名称:magento2,代码行数:34,代码来源:Design.php
示例8: testDeleteRecordsOlderThen
/**
* @return void
*/
public function testDeleteRecordsOlderThen()
{
$timestamp = 12345;
$this->resourceMock->expects($this->once())->method('getConnection')->willReturn($this->dbAdapterMock);
$this->dbAdapterMock->expects($this->once())->method('delete')->with($this->model->getMainTable(), ['created_at < ?' => $this->dateTimeMock->formatDate($timestamp)])->willReturnSelf();
$this->assertEquals($this->model, $this->model->deleteRecordsOlderThen($timestamp));
}
开发者ID:dragonsword007008,项目名称:magento2,代码行数:10,代码来源:PasswordResetRequestEventTest.php
示例9: updateSpecificCoupons
/**
* Update auto generated Specific Coupon if it's rule changed
*
* @param \Magento\SalesRule\Model\Rule $rule
* @return $this
*/
public function updateSpecificCoupons(\Magento\SalesRule\Model\Rule $rule)
{
if (!$rule || !$rule->getId() || !$rule->hasDataChanges()) {
return $this;
}
$updateArray = [];
if ($rule->dataHasChangedFor('uses_per_coupon')) {
$updateArray['usage_limit'] = $rule->getUsesPerCoupon();
}
if ($rule->dataHasChangedFor('uses_per_customer')) {
$updateArray['usage_per_customer'] = $rule->getUsesPerCustomer();
}
$ruleNewDate = $this->dateTime->formatDate($rule->getToDate());
$ruleOldDate = $this->dateTime->formatDate($rule->getOrigData('to_date'));
if ($ruleNewDate != $ruleOldDate) {
$updateArray['expiration_date'] = $rule->getToDate();
}
if (!empty($updateArray)) {
$this->getConnection()->update($this->getTable('salesrule_coupon'), $updateArray, ['rule_id = ?' => $rule->getId(), 'generated_by_dotmailer is null']);
}
//update coupons generated by dotmailer. not to change expiration date
$dotmailerUpdateArray = $updateArray;
unset($dotmailerUpdateArray['expiration_date']);
if (!empty($dotmailerUpdateArray)) {
$this->getConnection()->update($this->getTable('salesrule_coupon'), $dotmailerUpdateArray, ['rule_id = ?' => $rule->getId(), 'generated_by_dotmailer is 1']);
}
return $this;
}
开发者ID:dotmailer,项目名称:dotmailer-magento2-extension,代码行数:34,代码来源:Coupon.php
示例10: testBeforeSave
public function testBeforeSave()
{
$this->pageMock->expects($this->any())->method('getData')->willReturnMap([['identifier', null, 'test'], ['custom_theme_from', null, null], ['custom_theme_to', null, '10/02/2016']]);
$this->dateTimeMock->expects($this->once())->method('formatDate')->with('10/02/2016')->willReturn('10 Feb 2016');
$this->pageMock->expects($this->any())->method('setData')->withConsecutive(['custom_theme_from', null], ['custom_theme_to', '10 Feb 2016']);
$this->model->beforeSave($this->pageMock);
}
开发者ID:Doability,项目名称:magento2dev,代码行数:7,代码来源:PageTest.php
示例11: _beforeSave
/**
* Process role before saving
*
* @param \Magento\Framework\Model\AbstractModel $role
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $role)
{
if (!$role->getId()) {
$role->setCreated($this->dateTime->formatDate(true));
}
$role->setModified($this->dateTime->formatDate(true));
if ($role->getId() == '') {
if ($role->getIdFieldName()) {
$role->unsetData($role->getIdFieldName());
} else {
$role->unsetData('id');
}
}
if (!$role->getTreeLevel()) {
if ($role->getPid() > 0) {
$select = $this->_getReadAdapter()->select()->from($this->getMainTable(), array('tree_level'))->where("{$this->getIdFieldName()} = :pid");
$binds = array('pid' => (int) $role->getPid());
$treeLevel = $this->_getReadAdapter()->fetchOne($select, $binds);
} else {
$treeLevel = 0;
}
$role->setTreeLevel($treeLevel + 1);
}
if ($role->getName()) {
$role->setRoleName($role->getName());
}
return $this;
}
开发者ID:Atlis,项目名称:docker-magento2,代码行数:34,代码来源:Role.php
示例12: report
/**
* Reports Modules and module changes to the database reporting_module_status table
*
* @return \Magento\NewRelicReporting\Model\Cron\ReportModulesInfo
*/
public function report()
{
if ($this->config->isNewRelicEnabled()) {
$moduleData = $this->collect->getModuleData();
if (count($moduleData['changes']) > 0) {
foreach ($moduleData['changes'] as $change) {
switch ($change['type']) {
case Config::ENABLED:
$modelData = ['type' => Config::MODULE_ENABLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)];
break;
case Config::DISABLED:
$modelData = ['type' => Config::MODULE_DISABLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)];
break;
case Config::INSTALLED:
$modelData = ['type' => Config::MODULE_INSTALLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)];
break;
case Config::UNINSTALLED:
$modelData = ['type' => Config::MODULE_UNINSTALLED, 'action' => $this->jsonEncoder->encode($change), 'updated_at' => $this->dateTime->formatDate(true)];
break;
}
/** @var \Magento\NewRelicReporting\Model\System $systemModel */
$systemModel = $this->systemFactory->create();
$systemModel->setData($modelData);
$systemModel->save();
}
}
}
return $this;
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:34,代码来源:ReportModulesInfo.php
示例13: testReportOrderPlaced
/**
* Test case when module is enabled in config
*
* @return void
*/
public function testReportOrderPlaced()
{
$testCustomerId = 1;
$testTotal = '1.00';
$testBaseTotal = '1.00';
$testItemCount = null;
$testTotalQtyOrderedCount = 1;
$testUpdated = '1970-01-01 00:00:00';
/** @var \Magento\Framework\Event\Observer|\PHPUnit_Framework_MockObject_MockObject $eventObserver */
$eventObserver = $this->getMockBuilder('Magento\\Framework\\Event\\Observer')->disableOriginalConstructor()->getMock();
$this->config->expects($this->once())->method('isNewRelicEnabled')->willReturn(true);
$this->dateTime->expects($this->once())->method('formatDate')->willReturn($testUpdated);
$event = $this->getMockBuilder('Magento\\Framework\\Event')->setMethods(['getOrder'])->disableOriginalConstructor()->getMock();
$eventObserver->expects($this->once())->method('getEvent')->willReturn($event);
$order = $this->getMockBuilder('Magento\\Sales\\Model\\Order')->disableOriginalConstructor()->getMock();
$event->expects($this->once())->method('getOrder')->willReturn($order);
$order->expects($this->once())->method('getCustomerId')->willReturn($testCustomerId);
$order->expects($this->once())->method('getGrandTotal')->willReturn($testTotal);
$order->expects($this->once())->method('getBaseGrandTotal')->willReturn($testBaseTotal);
$order->expects($this->once())->method('getTotalItemCount')->willReturn($testItemCount);
$order->expects($this->once())->method('getTotalQtyOrdered')->willReturn($testTotalQtyOrderedCount);
$this->ordersModel->expects($this->once())->method('setData')->with(['customer_id' => $testCustomerId, 'total' => $testTotal, 'total_base' => $testBaseTotal, 'item_count' => $testTotalQtyOrderedCount, 'updated_at' => $testUpdated])->willReturnSelf();
$this->ordersModel->expects($this->once())->method('save');
$this->model->execute($eventObserver);
}
开发者ID:whoople,项目名称:magento2-testing,代码行数:30,代码来源:ReportOrderPlacedTest.php
示例14: testBeforeSave
public function testBeforeSave()
{
$timeStamp = '0000';
$this->dateTimeMock->expects($this->exactly(2))->method('formatDate')->will($this->returnValue($timeStamp));
$this->integrationModel->beforeSave();
$this->assertEquals($timeStamp, $this->integrationModel->getCreatedAt());
$this->assertEquals($timeStamp, $this->integrationModel->getUpdatedAt());
}
开发者ID:nja78,项目名称:magento2,代码行数:8,代码来源:IntegrationTest.php
示例15: beforeSave
/**
* Set created date
*
* @param \Magento\Core\Model\Object $object
* @return $this
*/
public function beforeSave($object)
{
$attributeCode = $this->getAttribute()->getAttributeCode();
if ($object->isObjectNew() && is_null($object->getData($attributeCode))) {
$object->setData($attributeCode, $this->dateTime->now());
}
return $this;
}
开发者ID:aiesh,项目名称:magento2,代码行数:14,代码来源:Created.php
示例16: build
/**
* {@inheritdoc}
*/
public function build($productId)
{
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
$currentDate = $this->dateTime->formatDate($timestamp, false);
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$productTable = $this->resource->getTableName('catalog_product_entity');
return [$this->resource->getConnection()->select()->from(['parent' => $productTable], '')->joinInner(['link' => $this->resource->getTableName('catalog_product_relation')], "link.parent_id = parent.{$linkField}", [])->joinInner(['child' => $productTable], "child.entity_id = link.child_id", ['entity_id'])->joinInner(['t' => $this->resource->getTableName('catalogrule_product_price')], 't.product_id = child.entity_id', [])->where('parent.entity_id = ? ', $productId)->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())->where('t.rule_date = ?', $currentDate)->order('t.rule_price ' . Select::SQL_ASC)->limit(1)];
}
开发者ID:Doability,项目名称:magento2dev,代码行数:11,代码来源:LinkedProductSelectBuilderByCatalogRulePrice.php
示例17: testFilterExpiredSessions
/**
* @return void
*/
public function testFilterExpiredSessions()
{
$sessionLifeTime = '600';
$timestamp = time();
$this->securityConfigMock->expects($this->once())->method('getCurrentTimestamp')->willReturn($timestamp);
$this->collectionMock->expects($this->once())->method('addFieldToFilter')->with('updated_at', ['gt' => $this->dateTimeMock->formatDate($timestamp - $sessionLifeTime)])->willReturnSelf();
$this->assertEquals($this->collectionMock, $this->collectionMock->filterExpiredSessions($sessionLifeTime));
}
开发者ID:dragonsword007008,项目名称:magento2,代码行数:11,代码来源:CollectionTest.php
示例18: _beforeSave
/**
* Prepare data to be saved to database
* @param \Magento\Framework\Model\AbstractModel|\Magento\Framework\Object $object
*
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
if ($object->isObjectNew()) {
$object->setCreatedAt($this->dateTime->formatDate(true));
}
$object->setUpdatedAt($this->dateTime->formatDate(true));
return $this;
}
开发者ID:nja78,项目名称:magento2,代码行数:14,代码来源:Bookmark.php
示例19: 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
示例20: deleteOldEntries
/**
* Delete old entries
*
* @param int $minutes
* @return int
*/
public function deleteOldEntries($minutes)
{
if ($minutes > 0) {
$adapter = $this->_getWriteAdapter();
return $adapter->delete($this->getMainTable(), $adapter->quoteInto('type = "' . \Magento\Integration\Model\Oauth\Token::TYPE_REQUEST . '" AND created_at <= ?', $this->_dateTime->formatDate(time() - $minutes * 60)));
} else {
return 0;
}
}
开发者ID:shabbirvividads,项目名称:magento2,代码行数:15,代码来源:Token.php
注:本文中的Magento\Framework\Stdlib\DateTime类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论