Skip to content

Commit 29389d0

Browse files
committed
ACP2E-2127: Date filter is not working in admin grid.
- Fixed the different workaround solution.
1 parent 8e7cae2 commit 29389d0

File tree

3 files changed

+68
-10
lines changed
  • app/code/Magento/Customer
  • lib/internal/Magento/Framework/Stdlib/DateTime

3 files changed

+68
-10
lines changed
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Customer\Ui\Component\Form\Element\DataType;
9+
10+
use Exception;
11+
use Magento\Ui\Component\Form\Element\DataType\Date as UiComponentDate;
12+
use Magento\Framework\Stdlib\DateTime\Intl\DateFormatterFactory;
13+
14+
/**
15+
* Format the filtered date in customer grid based on specific locale
16+
*/
17+
class Date
18+
{
19+
/**
20+
* @param DateFormatterFactory $dateFormatterFactory
21+
*/
22+
public function __construct(
23+
private DateFormatterFactory $dateFormatterFactory
24+
) {
25+
}
26+
27+
/**
28+
* Convert given filter date to specific date format based on locale
29+
*
30+
* @param UiComponentDate $subject
31+
* @param string $date
32+
* @param int $hour
33+
* @param int $minute
34+
* @param int $second
35+
* @param bool $setUtcTimeZone
36+
* @return array
37+
* @throws Exception
38+
*/
39+
public function beforeConvertDate(
40+
UiComponentDate $subject,
41+
string $date,
42+
int $hour,
43+
int $minute,
44+
int $second,
45+
bool $setUtcTimeZone
46+
): array {
47+
$formatter = $this->dateFormatterFactory->create(
48+
$subject->getLocale(),
49+
\IntlDateFormatter::SHORT,
50+
\IntlDateFormatter::NONE,
51+
date_default_timezone_get()
52+
);
53+
$formatter->setLenient(false);
54+
if (!$formatter->parse($date)) {
55+
$date = $formatter->formatObject(
56+
new \DateTime($date),
57+
$formatter->getPattern()
58+
);
59+
}
60+
$formatter->setLenient(true);
61+
return [$date, $hour, $minute, $second, $setUtcTimeZone];
62+
}
63+
}

app/code/Magento/Customer/etc/adminhtml/di.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,7 @@
4545
<plugin name="reindex_customer_grid_after_website_remove" type="Magento\Customer\Model\Plugin\CustomerGridIndexAfterWebsiteDelete" />
4646
<plugin name="deleteCustomerGroupExcludedWebsiteAfterWebsiteDelete" type="Magento\Customer\Model\Plugin\Website\DeleteCustomerGroupExcludedWebsite"/>
4747
</type>
48+
<type name="Magento\Ui\Component\Form\Element\DataType\Date">
49+
<plugin name="customerGridFormatFilterDate" type="Magento\Customer\Ui\Component\Form\Element\DataType\Date"/>
50+
</type>
4851
</config>

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,7 @@ public function date($date = null, $locale = null, $useTimezone = true, $include
196196
$includeTime ? \IntlDateFormatter::SHORT : \IntlDateFormatter::NONE,
197197
$timezone
198198
);
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();
199+
$date = $formatter->parse($date) ?: (new \DateTime($date))->getTimestamp();
208200
break;
209201
}
210202

@@ -288,7 +280,7 @@ public function isScopeDateInInterval($scope, $dateFrom = null, $dateTo = null)
288280
}
289281

290282
return !(!$this->_dateTime->isEmptyDate($dateFrom) && $scopeTimeStamp < $fromTimeStamp ||
291-
!$this->_dateTime->isEmptyDate($dateTo) && $scopeTimeStamp > $toTimeStamp);
283+
!$this->_dateTime->isEmptyDate($dateTo) && $scopeTimeStamp > $toTimeStamp);
292284
}
293285

294286
/**

0 commit comments

Comments
 (0)