12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Backend\Block\Widget\Grid\Column\Renderer;
- use Magento\Framework\Stdlib\DateTime\DateTimeFormatterInterface;
- /**
- * Backend grid item renderer date
- * @api
- * @deprecated 100.2.0 in favour of UI component implementation
- * @since 100.0.2
- */
- class Date extends \Magento\Backend\Block\Widget\Grid\Column\Renderer\AbstractRenderer
- {
- /**
- * @var int
- */
- protected $_defaultWidth = 160;
- /**
- * Date format string
- *
- * @var string
- */
- protected static $_format = null;
- /**
- * @var DateTimeFormatterInterface
- */
- protected $dateTimeFormatter;
- /**
- * @param \Magento\Backend\Block\Context $context
- * @param DateTimeFormatterInterface $dateTimeFormatter
- * @param array $data
- */
- public function __construct(
- \Magento\Backend\Block\Context $context,
- DateTimeFormatterInterface $dateTimeFormatter,
- array $data = []
- ) {
- parent::__construct($context, $data);
- $this->dateTimeFormatter = $dateTimeFormatter;
- }
- /**
- * Retrieve date format
- *
- * @return string
- * @deprecated 100.1.0
- */
- protected function _getFormat()
- {
- $format = $this->getColumn()->getFormat();
- if ($format === null) {
- if (self::$_format === null) {
- try {
- self::$_format = $this->_localeDate->getDateFormat(
- \IntlDateFormatter::MEDIUM
- );
- } catch (\Exception $e) {
- $this->_logger->critical($e);
- }
- }
- $format = self::$_format;
- }
- return $format;
- }
- /**
- * Renders grid column
- *
- * @param \Magento\Framework\DataObject $row
- * @return string
- */
- public function render(\Magento\Framework\DataObject $row)
- {
- $format = $this->getColumn()->getFormat();
- $date = $this->_getValue($row);
- if ($date) {
- if (!($date instanceof \DateTimeInterface)) {
- $date = new \DateTime($date);
- }
- return $this->_localeDate->formatDateTime(
- $date,
- $format ?: \IntlDateFormatter::MEDIUM,
- \IntlDateFormatter::NONE,
- null,
- $this->getColumn()->getTimezone() === false ? 'UTC' : null
- );
- }
- return $this->getColumn()->getDefault();
- }
- }
|