Skip to content

Commit db905b8

Browse files
committed
MC-17269: Date format grid is not based on the locale defined in the back-office
1 parent ee6bc37 commit db905b8

File tree

2 files changed

+48
-1
lines changed
  • app/code/Magento/Ui

2 files changed

+48
-1
lines changed

app/code/Magento/Ui/Component/Listing/Columns/Date.php

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,12 @@
33
* Copyright © Magento, Inc. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
6+
67
namespace Magento\Ui\Component\Listing\Columns;
78

9+
use Magento\Framework\App\ObjectManager;
10+
use Magento\Framework\Locale\Bundle\DataBundle;
11+
use Magento\Framework\Locale\ResolverInterface;
812
use Magento\Framework\Stdlib\BooleanUtils;
913
use Magento\Framework\View\Element\UiComponent\ContextInterface;
1014
use Magento\Framework\View\Element\UiComponentFactory;
@@ -28,11 +32,28 @@ class Date extends Column
2832
*/
2933
private $booleanUtils;
3034

35+
/**
36+
* @var ResolverInterface
37+
*/
38+
private $localeResolver;
39+
40+
/**
41+
* @var string
42+
*/
43+
private $locale;
44+
45+
/**
46+
* @var DataBundle
47+
*/
48+
private $dataBundle;
49+
3150
/**
3251
* @param ContextInterface $context
3352
* @param UiComponentFactory $uiComponentFactory
3453
* @param TimezoneInterface $timezone
3554
* @param BooleanUtils $booleanUtils
55+
* @param ResolverInterface $localeResolver
56+
* @param DataBundle $dataBundle
3657
* @param array $components
3758
* @param array $data
3859
*/
@@ -41,11 +62,16 @@ public function __construct(
4162
UiComponentFactory $uiComponentFactory,
4263
TimezoneInterface $timezone,
4364
BooleanUtils $booleanUtils,
65+
ResolverInterface $localeResolver = null,
66+
DataBundle $dataBundle = null,
4467
array $components = [],
4568
array $data = []
4669
) {
4770
$this->timezone = $timezone;
4871
$this->booleanUtils = $booleanUtils;
72+
$this->localeResolver = $localeResolver ?? ObjectManager::getInstance()->get(ResolverInterface::class);
73+
$this->locale = $this->localeResolver->getLocale();
74+
$this->dataBundle = $dataBundle ?? ObjectManager::getInstance()->get(DataBundle::class);
4975
parent::__construct($context, $uiComponentFactory, $components, $data);
5076
}
5177

@@ -65,6 +91,25 @@ public function prepare()
6591
]
6692
]
6793
];
94+
95+
$localeData = $this->dataBundle->get($this->locale);
96+
/** @var \ResourceBundle $monthsData */
97+
$monthsData = $localeData['calendar']['gregorian']['monthNames'];
98+
$months = array_values(iterator_to_array($monthsData['format']['wide']));
99+
$monthsShort = array_values(
100+
iterator_to_array(
101+
null !== $monthsData->get('format')->get('abbreviated')
102+
? $monthsData['format']['abbreviated']
103+
: $monthsData['format']['wide']
104+
)
105+
);
106+
107+
$config['storeLocale'] = $this->locale;
108+
$config['dateData'] = [
109+
'months' => $months,
110+
'monthsShort' => $monthsShort,
111+
];
112+
$config['dateFormat'] = $this->timezone->getDateTimeFormat(\IntlDateFormatter::MEDIUM);
68113
$this->setData('config', $config);
69114

70115
parent::prepare();
@@ -78,7 +123,7 @@ public function prepareDataSource(array $dataSource)
78123
if (isset($dataSource['data']['items'])) {
79124
foreach ($dataSource['data']['items'] as & $item) {
80125
if (isset($item[$this->getData('name')])
81-
&& $item[$this->getData('name')] !== "0000-00-00 00:00:00"
126+
&& $item[$this->getData('name')] !== "0000-00-00 00:00:00"
82127
) {
83128
$date = $this->timezone->date(new \DateTime($item[$this->getData('name')]));
84129
$timezone = isset($this->getConfiguration()['timezone'])

app/code/Magento/Ui/view/base/web/js/grid/columns/date.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ define([
1717
defaults: {
1818
dateFormat: 'MMM d, YYYY h:mm:ss A'
1919
},
20+
dateData: [],
2021

2122
/**
2223
* Overrides base method to normalize date format.
@@ -37,6 +38,7 @@ define([
3738
* @returns {String} Formatted date.
3839
*/
3940
getLabel: function (value, format) {
41+
moment.locale(this.storeLocale, {...this.dateData});
4042
var date = moment(this._super());
4143

4244
date = date.isValid() && value[this.index] ?

0 commit comments

Comments
 (0)