Skip to content

Commit 9f57557

Browse files
committed
ACP2E-2127: Date filter is not working in admin grid.
- Fixed the CR comments.
1 parent 38d01fd commit 9f57557

File tree

3 files changed

+13
-23
lines changed

3 files changed

+13
-23
lines changed

app/code/Magento/Ui/Component/Filters/Type/Date.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,7 @@ protected function applyFilter()
8686
if (is_array($value)) {
8787
if (isset($value['from'])) {
8888
if (!$this->getData('config/options/showsTime') && $this->getData('config/dateFormat')) {
89-
$value['from'] = $this->wrappedComponent->convertDateFormat(
90-
$value['from'],
91-
$this->getData('config/dateFormat')
92-
);
89+
$value['from'] = $this->wrappedComponent->convertDateFormat($value['from']);
9390
}
9491
$this->applyFilterByType(
9592
'gteq',
@@ -99,10 +96,7 @@ protected function applyFilter()
9996

10097
if (isset($value['to'])) {
10198
if (!$this->getData('config/options/showsTime') && $this->getData('config/dateFormat')) {
102-
$value['to'] = $this->wrappedComponent->convertDateFormat(
103-
$value['to'],
104-
$this->getData('config/dateFormat')
105-
);
99+
$value['to'] = $this->wrappedComponent->convertDateFormat($value['to']);
106100
}
107101
$this->applyFilterByType(
108102
'lteq',

app/code/Magento/Ui/Component/Form/Element/DataType/Date.php

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ class Date extends AbstractDataType
1717
{
1818
public const NAME = 'date';
1919

20-
public const CUSTOM_DATE_FORMAT = 'Y-MM-dd';
21-
2220
/**
2321
* Current locale
2422
*
@@ -151,20 +149,19 @@ public function convertDatetime(string $date, bool $setUtcTimezone = true): ?\Da
151149
* Convert given date to specific date format based on locale
152150
*
153151
* @param string $date
154-
* @param string $dateFormat
155152
* @return String
156153
*/
157-
public function convertDateFormat(string $date, string $dateFormat): String
154+
public function convertDateFormat(string $date): String
158155
{
159-
if ($dateFormat === self::CUSTOM_DATE_FORMAT) {
160-
$date = $this->localeDate->formatDateTime(
161-
$date,
162-
null,
163-
null,
164-
$this->getLocale(),
165-
date_default_timezone_get()
166-
);
156+
if ($this->getLocale() === 'en_GB' && str_contains($date, '/')) {
157+
$date = \DateTime::createFromFormat('d/m/Y', $date);
167158
}
168-
return $date;
159+
return $this->localeDate->formatDateTime(
160+
$date,
161+
null,
162+
null,
163+
$this->getLocale(),
164+
date_default_timezone_get()
165+
);
169166
}
170167
}

app/code/Magento/Ui/Test/Unit/Component/Form/Element/DataType/DateTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,6 @@ public function testConvertDatetime(string $dateStr, bool $setUtcTimeZone, strin
180180
public function testConvertDateFormat()
181181
{
182182
$dateStr = '2023-10-11';
183-
$dateFormat = 'Y-MM-dd';
184183
$this->date = $this->objectManagerHelper->getObject(
185184
Date::class,
186185
[
@@ -195,7 +194,7 @@ public function testConvertDateFormat()
195194
->willReturn(date_format(date_create($dateStr), 'm/d/Y'));
196195
$this->assertEquals(
197196
date_format(date_create($dateStr), 'm/d/Y'),
198-
$this->date->convertDateFormat($dateStr, $dateFormat)
197+
$this->date->convertDateFormat($dateStr)
199198
);
200199
}
201200

0 commit comments

Comments
 (0)