Skip to content

Commit 6ce291b

Browse files
committed
ACP2E-2127: Date filter is not working in admin grid.
- Fixed the CR comments.
1 parent 55f401c commit 6ce291b

File tree

5 files changed

+123
-247
lines changed
  • app/code/Magento

5 files changed

+123
-247
lines changed

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

Lines changed: 0 additions & 167 deletions
This file was deleted.

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

Lines changed: 0 additions & 73 deletions
This file was deleted.

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,4 @@
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>
5148
</config>

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

Lines changed: 42 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@
55
*/
66
namespace Magento\Ui\Component\Form\Element\DataType;
77

8+
use Exception;
89
use Magento\Framework\Locale\ResolverInterface;
910
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1011
use Magento\Framework\View\Element\UiComponentInterface;
1112
use Magento\Framework\View\Element\UiComponent\ContextInterface;
13+
use Magento\Framework\Stdlib\DateTime\Intl\DateFormatterFactory;
14+
use Magento\Framework\App\ObjectManager;
1215

1316
/**
1417
* UI component date type
1518
*/
1619
class Date extends AbstractDataType
1720
{
18-
const NAME = 'date';
21+
public const NAME = 'date';
1922

2023
/**
2124
* Current locale
@@ -25,7 +28,7 @@ class Date extends AbstractDataType
2528
protected $locale;
2629

2730
/**
28-
* Wrapped component
31+
* Wrapped component for date type
2932
*
3033
* @var UiComponentInterface
3134
*/
@@ -36,6 +39,11 @@ class Date extends AbstractDataType
3639
*/
3740
private $localeDate;
3841

42+
/**
43+
* @var DateFormatterFactory
44+
*/
45+
private $dateFormatterFactory;
46+
3947
/**
4048
* Constructor
4149
*
@@ -44,17 +52,21 @@ class Date extends AbstractDataType
4452
* @param ResolverInterface $localeResolver
4553
* @param array $components
4654
* @param array $data
55+
* @param DateFormatterFactory|null $dateFormatterFactory
4756
*/
4857
public function __construct(
4958
ContextInterface $context,
5059
TimezoneInterface $localeDate,
5160
ResolverInterface $localeResolver,
5261
array $components = [],
53-
array $data = []
62+
array $data = [],
63+
?DateFormatterFactory $dateFormatterFactory = null
5464
) {
5565
$this->locale = $localeResolver->getLocale();
5666
$this->localeDate = $localeDate;
5767
parent::__construct($context, $components, $data);
68+
$objectManager = ObjectManager::getInstance();
69+
$this->dateFormatterFactory = $dateFormatterFactory ?? $objectManager->get(DateFormatterFactory::class);
5870
}
5971

6072
/**
@@ -111,14 +123,15 @@ public function getComponentName()
111123
public function convertDate($date, $hour = 0, $minute = 0, $second = 0, $setUtcTimeZone = true)
112124
{
113125
try {
126+
$date = $this->convertDateFormat($date);
114127
$dateObj = $this->localeDate->date($date, $this->getLocale(), false, false);
115128
$dateObj->setTime($hour, $minute, $second);
116129
//convert store date to default date in UTC timezone without DST
117130
if ($setUtcTimeZone) {
118131
$dateObj->setTimezone(new \DateTimeZone('UTC'));
119132
}
120133
return $dateObj;
121-
} catch (\Exception $e) {
134+
} catch (Exception $e) {
122135
return null;
123136
}
124137
}
@@ -144,4 +157,29 @@ public function convertDatetime(string $date, bool $setUtcTimezone = true): ?\Da
144157
return null;
145158
}
146159
}
160+
161+
/**
162+
* Convert given date to specific date format based on locale
163+
*
164+
* @param string $date
165+
* @return String
166+
* @throws Exception
167+
*/
168+
public function convertDateFormat(string $date): String
169+
{
170+
$formatter = $this->dateFormatterFactory->create(
171+
$this->getLocale(),
172+
\IntlDateFormatter::SHORT,
173+
\IntlDateFormatter::NONE,
174+
date_default_timezone_get()
175+
);
176+
$formatter->setLenient(false);
177+
if (!$formatter->parse($date)) {
178+
$date = $formatter->formatObject(
179+
new \DateTime($date),
180+
$formatter->getPattern()
181+
);
182+
}
183+
return $date;
184+
}
147185
}

0 commit comments

Comments
 (0)