Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Date.php
Go to the documentation of this file.
1 <?php
7 
12 
17 class Date extends Column
18 {
22  protected $timezone;
23 
27  private $booleanUtils;
28 
37  public function __construct(
41  BooleanUtils $booleanUtils,
42  array $components = [],
43  array $data = []
44  ) {
45  $this->timezone = $timezone;
46  $this->booleanUtils = $booleanUtils;
47  parent::__construct($context, $uiComponentFactory, $components, $data);
48  }
49 
53  public function prepareDataSource(array $dataSource)
54  {
55  if (isset($dataSource['data']['items'])) {
56  foreach ($dataSource['data']['items'] as & $item) {
57  if (isset($item[$this->getData('name')])
58  && $item[$this->getData('name')] !== "0000-00-00 00:00:00"
59  ) {
60  $date = $this->timezone->date(new \DateTime($item[$this->getData('name')]));
61  $timezone = isset($this->getConfiguration()['timezone'])
62  ? $this->booleanUtils->convert($this->getConfiguration()['timezone'])
63  : true;
64  if (!$timezone) {
65  $date = new \DateTime($item[$this->getData('name')]);
66  }
67  $item[$this->getData('name')] = $date->format('Y-m-d H:i:s');
68  }
69  }
70  }
71 
72  return $dataSource;
73  }
74 }
prepareDataSource(array $dataSource)
Definition: Date.php:53
__construct(ContextInterface $context, UiComponentFactory $uiComponentFactory, TimezoneInterface $timezone, BooleanUtils $booleanUtils, array $components=[], array $data=[])
Definition: Date.php:37