Skip to content

Commit 369aff2

Browse files
committed
ACP2E-2127: Date filter is not working in admin grid.
- Fixed the workaround solution.
1 parent 55da81c commit 369aff2

File tree

3 files changed

+16
-51
lines changed

3 files changed

+16
-51
lines changed

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
*/
1717
class Date extends AbstractFilter
1818
{
19-
public const NAME = 'filter_date';
19+
const NAME = 'filter_date';
2020

21-
public const COMPONENT = 'date';
21+
const COMPONENT = 'date';
2222

2323
/**
24-
* Wrapped component for date grid filter UI Component
24+
* Wrapped component
2525
*
2626
* @var DataTypeDate
2727
*/
2828
protected $wrappedComponent;
2929

3030
/**
31-
* Date format for date grid filter UI Component
31+
* Date format
3232
*
3333
* @var string
3434
* @since 100.1.2
@@ -72,7 +72,6 @@ public function prepare()
7272
* Apply filter
7373
*
7474
* @return void
75-
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
7675
*/
7776
protected function applyFilter()
7877
{
@@ -85,19 +84,13 @@ protected function applyFilter()
8584

8685
if (is_array($value)) {
8786
if (isset($value['from'])) {
88-
if (!$this->getData('config/options/showsTime') && $this->getData('config/dateFormat')) {
89-
$value['from'] = $this->wrappedComponent->convertDateFormat($value['from']);
90-
}
9187
$this->applyFilterByType(
9288
'gteq',
9389
$this->convertDatetime((string)$value['from'])
9490
);
9591
}
9692

9793
if (isset($value['to'])) {
98-
if (!$this->getData('config/options/showsTime') && $this->getData('config/dateFormat')) {
99-
$value['to'] = $this->wrappedComponent->convertDateFormat($value['to']);
100-
}
10194
$this->applyFilterByType(
10295
'lteq',
10396
$this->convertDatetime((string)$value['to'], 23, 59, 59)

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

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,13 @@
99
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1010
use Magento\Framework\View\Element\UiComponentInterface;
1111
use Magento\Framework\View\Element\UiComponent\ContextInterface;
12-
use Magento\Framework\Stdlib\DateTime\Intl\DateFormatterFactory;
13-
use Magento\Framework\App\ObjectManager;
1412

1513
/**
1614
* UI component date type
1715
*/
1816
class Date extends AbstractDataType
1917
{
20-
public const NAME = 'date';
18+
const NAME = 'date';
2119

2220
/**
2321
* Current locale
@@ -27,7 +25,7 @@ class Date extends AbstractDataType
2725
protected $locale;
2826

2927
/**
30-
* Wrapped component for date type
28+
* Wrapped component
3129
*
3230
* @var UiComponentInterface
3331
*/
@@ -38,11 +36,6 @@ class Date extends AbstractDataType
3836
*/
3937
private $localeDate;
4038

41-
/**
42-
* @var DateFormatterFactory
43-
*/
44-
private $dateFormatterFactory;
45-
4639
/**
4740
* Constructor
4841
*
@@ -51,21 +44,17 @@ class Date extends AbstractDataType
5144
* @param ResolverInterface $localeResolver
5245
* @param array $components
5346
* @param array $data
54-
* @param DateFormatterFactory|null $dateFormatterFactory
5547
*/
5648
public function __construct(
5749
ContextInterface $context,
5850
TimezoneInterface $localeDate,
5951
ResolverInterface $localeResolver,
6052
array $components = [],
61-
array $data = [],
62-
?DateFormatterFactory $dateFormatterFactory = null
53+
array $data = []
6354
) {
6455
$this->locale = $localeResolver->getLocale();
6556
$this->localeDate = $localeDate;
6657
parent::__construct($context, $components, $data);
67-
$objectManager = ObjectManager::getInstance();
68-
$this->dateFormatterFactory = $dateFormatterFactory ?? $objectManager->get(DateFormatterFactory::class);
6958
}
7059

7160
/**
@@ -155,29 +144,4 @@ public function convertDatetime(string $date, bool $setUtcTimezone = true): ?\Da
155144
return null;
156145
}
157146
}
158-
159-
/**
160-
* Convert given date to specific date format based on locale
161-
*
162-
* @param string $date
163-
* @return String
164-
*/
165-
public function convertDateFormat(string $date): String
166-
{
167-
$formatter = $this->dateFormatterFactory->create(
168-
$this->getLocale(),
169-
\IntlDateFormatter::SHORT,
170-
\IntlDateFormatter::NONE,
171-
date_default_timezone_get()
172-
);
173-
$formatter->setLenient(false);
174-
if (!$formatter->parse($date)) {
175-
$date = $formatter->formatObject(
176-
new \DateTime($date),
177-
$formatter->getPattern()
178-
);
179-
}
180-
$formatter->setLenient(true);
181-
return $date;
182-
}
183147
}

lib/internal/Magento/Framework/Stdlib/DateTime/Timezone.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,15 @@ public function date($date = null, $locale = null, $useTimezone = true, $include
196196
$includeTime ? \IntlDateFormatter::SHORT : \IntlDateFormatter::NONE,
197197
$timezone
198198
);
199-
$date = $formatter->parse($date) ?: (new \DateTime($date))->getTimestamp();
199+
$formatter->setLenient(false);
200+
if (!$formatter->parse($date)) {
201+
$date = $formatter->formatObject(
202+
new \DateTime($date),
203+
$formatter->getPattern()
204+
);
205+
}
206+
$formatter->setLenient(true);
207+
$date = $formatter->parse() ?: (new \DateTime($date))->getTimestamp();
200208
break;
201209
}
202210

0 commit comments

Comments
 (0)