本文整理汇总了PHP中Magento\Framework\Stdlib\DateTime\DateTime::date方法的典型用法代码示例。如果您正苦于以下问题:PHP DateTime::date方法的具体用法?PHP DateTime::date怎么用?PHP DateTime::date使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Stdlib\DateTime\DateTime
的用法示例。
在下文中一共展示了DateTime::date方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testDate
public function testDate()
{
$time = 1403858418;
$this->localeDate->expects($this->any())->method('date')->with($time)->will($this->returnValue($this->date));
$this->assertSame('2014-06-26', $this->dateTime->date('Y-m-d', $time));
$this->assertSame('2014-06-26 11:22:29', $this->dateTime->date(null, $time));
}
示例2: 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('*/*/');
}
示例3: 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');
}
示例4: roundTime
/**
* @param int $timeStamp
* @return int
*/
private function roundTime($timeStamp)
{
if (is_numeric($timeStamp) && $timeStamp != 0) {
$timeStamp = $this->dateTime->timestamp($this->dateTime->date('Y-m-d 00:00:00', $timeStamp));
}
return $timeStamp;
}
示例5: _beforeSave
/**
* before save callback
*
* @param \Magento\Framework\Model\AbstractModel|\Mageplaza\Blog\Model\Post $object
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
$object->setUpdatedAt($this->date->date());
if ($object->isObjectNew()) {
$object->setCreatedAt($this->date->date());
}
if ($object->isObjectNew()) {
$count = 0;
$objName = $object->getName();
if ($object->getUrlKey()) {
$urlKey = $object->getUrlKey();
} else {
$urlKey = $this->generateUrlKey($objName, $count);
}
while ($this->checkUrlKey($urlKey)) {
$count++;
$urlKey = $this->generateUrlKey($urlKey, $count);
}
$object->setUrlKey($urlKey);
} else {
$objectId = $object->getId();
$count = 0;
$objName = $object->getName();
if ($object->getUrlKey()) {
$urlKey = $object->getUrlKey();
} else {
$urlKey = $this->generateUrlKey($objName, $count);
}
while ($this->checkUrlKey($urlKey, $objectId)) {
$count++;
$urlKey = $this->generateUrlKey($urlKey, $count);
}
$object->setUrlKey($urlKey);
}
}
示例6: getYears
/**
* Retrieve array of available years
*
* @return array
* @api
*/
public function getYears()
{
$years = [];
$first = (int) $this->_date->date('Y');
for ($index = 0; $index <= self::YEARS_RANGE; $index++) {
$year = $first + $index;
$years[$year] = $year;
}
return $years;
}
示例7: collectFileInfo
/**
* Collect file info
*
* Return array(
* filename => string
* content => string|bool
* update_time => string
* directory => string
*
* @param string $mediaDirectory
* @param string $path
* @return array
* @throws \Magento\Framework\Exception\LocalizedException
*/
public function collectFileInfo($mediaDirectory, $path)
{
$path = ltrim($path, '\\/');
$fullPath = $mediaDirectory . '/' . $path;
$dir = $this->filesystem->getDirectoryRead(DirectoryList::MEDIA);
$relativePath = $dir->getRelativePath($fullPath);
if (!$dir->isFile($relativePath)) {
throw new \Magento\Framework\Exception\LocalizedException(__('File %1 does not exist', $fullPath));
}
if (!$dir->isReadable($relativePath)) {
throw new \Magento\Framework\Exception\LocalizedException(__('File %1 is not readable', $fullPath));
}
$path = str_replace(['/', '\\'], '/', $path);
$directory = dirname($path);
if ($directory == '.') {
$directory = null;
}
return ['filename' => basename($path), 'content' => $dir->readFile($relativePath), 'update_time' => $this->_date->date(), 'directory' => $directory];
}
示例8: _afterSave
/**
* Save report rows collected in settlement model
*
* @param \Magento\Framework\Model\AbstractModel|\Magento\Paypal\Model\Report\Settlement $object
* @return $this
*/
protected function _afterSave(\Magento\Framework\Model\AbstractModel $object)
{
$rows = $object->getRows();
if (is_array($rows)) {
$adapter = $this->_getWriteAdapter();
$reportId = (int) $object->getId();
try {
$adapter->beginTransaction();
if ($reportId) {
$adapter->delete($this->_rowsTable, array('report_id = ?' => $reportId));
}
foreach (array_keys($rows) as $key) {
/**
* Converting dates
*/
$completionDate = new \Magento\Framework\Stdlib\DateTime\Date($rows[$key]['transaction_completion_date']);
$rows[$key]['transaction_completion_date'] = $this->_coreDate->date(null, $completionDate->getTimestamp());
$initiationDate = new \Magento\Framework\Stdlib\DateTime\Date($rows[$key]['transaction_initiation_date']);
$rows[$key]['transaction_initiation_date'] = $this->_coreDate->date(null, $initiationDate->getTimestamp());
/*
* Converting numeric
*/
$rows[$key]['fee_amount'] = (double) $rows[$key]['fee_amount'];
/*
* Setting reportId
*/
$rows[$key]['report_id'] = $reportId;
}
if (!empty($rows)) {
$adapter->insertMultiple($this->_rowsTable, $rows);
}
$adapter->commit();
} catch (\Exception $e) {
$adapter->rollback();
}
}
return $this;
}
示例9: addWebsiteGroupDateFilter
/**
* Filter collection by website(s), customer group(s) and date.
* Filter collection to only active rules.
* Sorting is not involved
*
* @param int $websiteId
* @param int $customerGroupId
* @param string|null $now
* @use $this->addWebsiteFilter()
* @return $this
*/
public function addWebsiteGroupDateFilter($websiteId, $customerGroupId, $now = null)
{
if (!$this->getFlag('website_group_date_filter')) {
if (is_null($now)) {
$now = $this->_date->date('Y-m-d');
}
$this->addWebsiteFilter($websiteId);
$entityInfo = $this->_getAssociatedEntityInfo('customer_group');
$connection = $this->getConnection();
$this->getSelect()->joinInner(['customer_group_ids' => $this->getTable($entityInfo['associations_table'])], $connection->quoteInto('main_table.' . $entityInfo['rule_id_field'] . ' = customer_group_ids.' . $entityInfo['rule_id_field'] . ' AND customer_group_ids.' . $entityInfo['entity_id_field'] . ' = ?', (int) $customerGroupId), [])->where('from_date is null or from_date <= ?', $now)->where('to_date is null or to_date >= ?', $now);
$this->addIsActiveFilter();
$this->setFlag('website_group_date_filter', true);
}
return $this;
}
示例10: convertContentDateToTimestamp
/**
* Convert Google Content date format to unix timestamp
* Ex. 2008-12-08T16:57:23Z -> 2008-12-08 16:57:23
*
* @param string $gContentDate Google Content datetime
* @return int
*/
public function convertContentDateToTimestamp($gContentDate)
{
return $this->_date->date(null, $gContentDate);
}
示例11: _shipmentDetails
/**
* Generation Shipment Details Node according to origin region
*
* @param \Magento\Shipping\Model\Simplexml\Element $xml
* @param RateRequest $rawRequest
* @param string $originRegion
* @return void
*/
protected function _shipmentDetails($xml, $rawRequest, $originRegion = '')
{
$nodeShipmentDetails = $xml->addChild('ShipmentDetails', '', '');
$nodeShipmentDetails->addChild('NumberOfPieces', count($rawRequest->getPackages()));
if ($originRegion) {
$nodeShipmentDetails->addChild('CurrencyCode', $this->_storeManager->getWebsite($this->_request->getWebsiteId())->getBaseCurrencyCode());
}
$nodePieces = $nodeShipmentDetails->addChild('Pieces', '', '');
/*
* Package type
* EE (DHL Express Envelope), OD (Other DHL Packaging), CP (Custom Packaging)
* DC (Document), DM (Domestic), ED (Express Document), FR (Freight)
* BD (Jumbo Document), BP (Jumbo Parcel), JD (Jumbo Junior Document)
* JP (Jumbo Junior Parcel), PA (Parcel), DF (DHL Flyer)
*/
$i = 0;
foreach ($rawRequest->getPackages() as $package) {
$nodePiece = $nodePieces->addChild('Piece', '', '');
$packageType = 'EE';
if ($package['params']['container'] == self::DHL_CONTENT_TYPE_NON_DOC) {
$packageType = 'CP';
}
$nodePiece->addChild('PieceID', ++$i);
$nodePiece->addChild('PackageType', $packageType);
$nodePiece->addChild('Weight', round($package['params']['weight'], 1));
$params = $package['params'];
if ($params['width'] && $params['length'] && $params['height']) {
if (!$originRegion) {
$nodePiece->addChild('Width', round($params['width']));
$nodePiece->addChild('Height', round($params['height']));
$nodePiece->addChild('Depth', round($params['length']));
} else {
$nodePiece->addChild('Depth', round($params['length']));
$nodePiece->addChild('Width', round($params['width']));
$nodePiece->addChild('Height', round($params['height']));
}
}
$content = array();
foreach ($package['items'] as $item) {
$content[] = $item['name'];
}
$nodePiece->addChild('PieceContents', substr(implode(',', $content), 0, 34));
}
if (!$originRegion) {
$nodeShipmentDetails->addChild('Weight', round($rawRequest->getPackageWeight(), 1));
$nodeShipmentDetails->addChild('WeightUnit', substr($this->_getWeightUnit(), 0, 1));
$nodeShipmentDetails->addChild('GlobalProductCode', $rawRequest->getShippingMethod());
$nodeShipmentDetails->addChild('LocalProductCode', $rawRequest->getShippingMethod());
$nodeShipmentDetails->addChild('Date', $this->_coreDate->date('Y-m-d'));
$nodeShipmentDetails->addChild('Contents', 'DHL Parcel');
/**
* The DoorTo Element defines the type of delivery service that applies to the shipment.
* The valid values are DD (Door to Door), DA (Door to Airport) , AA and DC (Door to
* Door non-compliant)
*/
$nodeShipmentDetails->addChild('DoorTo', 'DD');
$nodeShipmentDetails->addChild('DimensionUnit', substr($this->_getDimensionUnit(), 0, 1));
if ($package['params']['container'] == self::DHL_CONTENT_TYPE_NON_DOC) {
$packageType = 'CP';
}
$nodeShipmentDetails->addChild('PackageType', $packageType);
if ($this->getConfigData('content_type') == self::DHL_CONTENT_TYPE_NON_DOC) {
$nodeShipmentDetails->addChild('IsDutiable', 'Y');
}
$nodeShipmentDetails->addChild('CurrencyCode', $this->_storeManager->getWebsite($this->_request->getWebsiteId())->getBaseCurrencyCode());
} else {
if ($package['params']['container'] == self::DHL_CONTENT_TYPE_NON_DOC) {
$packageType = 'CP';
}
$nodeShipmentDetails->addChild('PackageType', $packageType);
$nodeShipmentDetails->addChild('Weight', $rawRequest->getPackageWeight());
$nodeShipmentDetails->addChild('DimensionUnit', substr($this->_getDimensionUnit(), 0, 1));
$nodeShipmentDetails->addChild('WeightUnit', substr($this->_getWeightUnit(), 0, 1));
$nodeShipmentDetails->addChild('GlobalProductCode', $rawRequest->getShippingMethod());
$nodeShipmentDetails->addChild('LocalProductCode', $rawRequest->getShippingMethod());
/**
* The DoorTo Element defines the type of delivery service that applies to the shipment.
* The valid values are DD (Door to Door), DA (Door to Airport) , AA and DC (Door to
* Door non-compliant)
*/
$nodeShipmentDetails->addChild('DoorTo', 'DD');
$nodeShipmentDetails->addChild('Date', $this->_coreDate->date('Y-m-d'));
$nodeShipmentDetails->addChild('Contents', 'DHL Parcel TEST');
}
}
示例12: massAction
/**
* @param AbstractCollection $collection
* @return ResponseInterface
* @throws \Exception
* @throws \Zend_Pdf_Exception
*/
public function massAction(AbstractCollection $collection)
{
return $this->fileFactory->create(sprintf('creditmemo%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), $this->pdfCreditmemo->getPdf($collection)->render(), DirectoryList::VAR_DIR, 'application/pdf');
}
示例13: addDaysFilter
/**
* Adds filter on days in wishlist
*
* The $constraints may contain 'from' and 'to' indexes with number of days to look for items
*
* @param array $constraints
* @return $this
*/
public function addDaysFilter($constraints)
{
if (!is_array($constraints)) {
return $this;
}
$filter = array();
$now = $this->_date->date();
$gmtOffset = (int) $this->_date->getGmtOffset();
if (isset($constraints['from'])) {
$lastDay = new \Magento\Framework\Stdlib\DateTime\Date($now, \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
$lastDay->subSecond($gmtOffset)->subDay(intval($constraints['from']));
$filter['to'] = $lastDay;
}
if (isset($constraints['to'])) {
$firstDay = new \Magento\Framework\Stdlib\DateTime\Date($now, \Magento\Framework\Stdlib\DateTime::DATETIME_INTERNAL_FORMAT);
$firstDay->subSecond($gmtOffset)->subDay(intval($constraints['to']) + 1);
$filter['from'] = $firstDay;
}
if ($filter) {
$filter['datetime'] = true;
$this->addFieldToFilter('added_at', $filter);
}
return $this;
}
示例14: _beforeSave
/**
* before save callback
*
* @param \Magento\Framework\Model\AbstractModel|\Mageplaza\Blog\Model\Category $object
* @return $this
*/
protected function _beforeSave(\Magento\Framework\Model\AbstractModel $object)
{
$object->setUpdatedAt($this->date->date());
if ($object->isObjectNew()) {
$object->setCreatedAt($this->date->date());
}
/** @var \Mageplaza\Blog\Model\Category $object */
parent::_beforeSave($object);
if (!$object->getChildrenCount()) {
$object->setChildrenCount(0);
}
if ($object->isObjectNew()) {
if ($object->getPosition() === null) {
$object->setPosition($this->getMaxPosition($object->getPath()) + 1);
}
$path = explode('/', $object->getPath());
$level = count($path) - ($object->getId() ? 1 : 0);
$toUpdateChild = array_diff($path, [$object->getId()]);
if (!$object->hasPosition()) {
$object->setPosition($this->getMaxPosition(implode('/', $toUpdateChild)) + 1);
}
if (!$object->hasLevel()) {
$object->setLevel($level);
}
if (!$object->hasParentId() && $level && !$object->getInitialSetupFlag()) {
$object->setParentId($path[$level - 1]);
}
if (!$object->getId() && !$object->getInitialSetupFlag()) {
$object->setPath($object->getPath() . '/');
}
if (!$object->getInitialSetupFlag()) {
$this->getConnection()->update($this->getMainTable(), ['children_count' => new \Zend_Db_Expr('children_count+1')], ['category_id IN(?)' => $toUpdateChild]);
}
}
//Check Url Key
if ($object->isObjectNew()) {
$count = 0;
$objName = $object->getName();
if ($object->getUrlKey()) {
$urlKey = $object->getUrlKey();
} else {
$urlKey = $this->generateUrlKey($objName, $count);
}
while ($this->checkUrlKey($urlKey)) {
$count++;
$urlKey = $this->generateUrlKey($urlKey, $count);
}
$object->setUrlKey($urlKey);
} else {
$objectId = $object->getId();
$count = 0;
$objName = $object->getName();
if ($object->getUrlKey()) {
$urlKey = $object->getUrlKey();
} else {
$urlKey = $this->generateUrlKey($objName, $count);
}
while ($this->checkUrlKey($urlKey, $objectId)) {
$count++;
$urlKey = $this->generateUrlKey($urlKey, $count);
}
$object->setUrlKey($urlKey);
}
return $this;
}
示例15: massAction
/**
* Print all documents for selected orders
*
* @param AbstractCollection $collection
* @return ResponseInterface|\Magento\Backend\Model\View\Result\Redirect
*
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function massAction(AbstractCollection $collection)
{
$orderIds = $collection->getAllIds();
$shipments = $this->shipmentCollectionFactory->create()->setOrderFilter(['in' => $orderIds]);
$invoices = $this->invoiceCollectionFactory->create()->setOrderFilter(['in' => $orderIds]);
$creditmemos = $this->creditmemoCollectionFactory->create()->setOrderFilter(['in' => $orderIds]);
$documents = [];
if ($invoices->getSize()) {
$documents[] = $this->pdfInvoice->getPdf($invoices);
}
if ($shipments->getSize()) {
$documents[] = $this->pdfShipment->getPdf($shipments);
}
if ($creditmemos->getSize()) {
$documents[] = $this->pdfCreditmemo->getPdf($creditmemos);
}
if (empty($documents)) {
$this->messageManager->addError(__('There are no printable documents related to selected orders.'));
return $this->resultRedirectFactory->create()->setPath($this->getComponentRefererUrl());
}
$pdf = array_shift($documents);
foreach ($documents as $document) {
$pdf->pages = array_merge($pdf->pages, $document->pages);
}
return $this->fileFactory->create(sprintf('docs%s.pdf', $this->dateTime->date('Y-m-d_H-i-s')), $pdf->render(), DirectoryList::VAR_DIR, 'application/pdf');
}