本文整理汇总了PHP中Magento\Framework\Stdlib\DateTime类的典型用法代码示例。如果您正苦于以下问题:PHP DateTime类的具体用法?PHP DateTime怎么用?PHP DateTime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DateTime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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));
}
示例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);
}
示例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;
}
示例4: _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;
}
示例5: _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);
}
示例6: 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));
}
示例7: 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;
}
示例8: 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);
}
示例9: _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;
}
示例10: 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;
}
示例11: 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);
}
示例12: 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());
}
示例13: 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;
}
示例14: 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)];
}
示例15: 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));
}