Skip to content

Commit 164899b

Browse files
Merge remote-tracking branch 'origin/MAGETWO-59810-European-Date-Report-Generation-Throws-Exception' into BundledPR-Sep8
2 parents 1eaac8f + 181bc32 commit 164899b

File tree

8 files changed

+210
-67
lines changed

8 files changed

+210
-67
lines changed

app/code/Magento/Catalog/Controller/Adminhtml/Category.php

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,21 @@ abstract class Category extends \Magento\Backend\App\Action
1818
const ADMIN_RESOURCE = 'Magento_Catalog::categories';
1919

2020
/**
21-
* @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime
21+
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
2222
*/
23-
private $dateTimeFilter;
23+
protected $dateFilter;
24+
25+
/**
26+
* @param \Magento\Backend\App\Action\Context $context
27+
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date|null $dateFilter
28+
*/
29+
public function __construct(
30+
\Magento\Backend\App\Action\Context $context,
31+
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter = null
32+
) {
33+
$this->dateFilter = $dateFilter;
34+
parent::__construct($context);
35+
}
2436

2537
/**
2638
* Initialize requested category and put it into registry.
@@ -125,20 +137,6 @@ protected function ajaxRequestResponse($category, $resultPage)
125137
return $resultJson;
126138
}
127139

128-
/**
129-
* @return \Magento\Framework\Stdlib\DateTime\Filter\DateTime
130-
*
131-
* @deprecated 101.0.0
132-
*/
133-
private function getDateTimeFilter()
134-
{
135-
if ($this->dateTimeFilter === null) {
136-
$this->dateTimeFilter = \Magento\Framework\App\ObjectManager::getInstance()
137-
->get(\Magento\Framework\Stdlib\DateTime\Filter\DateTime::class);
138-
}
139-
return $this->dateTimeFilter;
140-
}
141-
142140
/**
143141
* Datetime data preprocessing
144142
*
@@ -154,7 +152,7 @@ protected function dateTimePreprocessing($category, $postData)
154152
foreach ($attributes as $attrKey => $attribute) {
155153
if ($attribute->getBackend()->getType() == 'datetime') {
156154
if (array_key_exists($attrKey, $postData) && $postData[$attrKey] != '') {
157-
$dateFieldFilters[$attrKey] = $this->getDateTimeFilter();
155+
$dateFieldFilters[$attrKey] = $this->dateFilter;
158156
}
159157
}
160158
}

app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Category
6161
* @param \Magento\Framework\Controller\Result\RawFactory $resultRawFactory
6262
* @param \Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory
6363
* @param \Magento\Framework\View\LayoutFactory $layoutFactory
64+
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
6465
* @param StoreManagerInterface $storeManager
6566
* @param \Magento\Eav\Model\Config $eavConfig
6667
*/
@@ -69,10 +70,11 @@ public function __construct(
6970
\Magento\Framework\Controller\Result\RawFactory $resultRawFactory,
7071
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
7172
\Magento\Framework\View\LayoutFactory $layoutFactory,
73+
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
7274
StoreManagerInterface $storeManager,
7375
\Magento\Eav\Model\Config $eavConfig = null
7476
) {
75-
parent::__construct($context);
77+
parent::__construct($context, $dateFilter);
7678
$this->resultRawFactory = $resultRawFactory;
7779
$this->resultJsonFactory = $resultJsonFactory;
7880
$this->layoutFactory = $layoutFactory;

dev/tests/integration/testsuite/Magento/Framework/Stdlib/DateTime/Filter/DataTest.php

Lines changed: 0 additions & 44 deletions
This file was deleted.
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Stdlib\DateTime\Filter;
7+
8+
use Magento\TestFramework\ObjectManager;
9+
10+
class DateTest extends \PHPUnit\Framework\TestCase
11+
{
12+
/**
13+
* @var ObjectManager
14+
*/
15+
private $objectManager;
16+
17+
/**
18+
* @var \Magento\Framework\Locale\ResolverInterface
19+
*/
20+
private $localeResolver;
21+
22+
/**
23+
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
24+
*/
25+
private $localeDate;
26+
27+
/**
28+
* @var \Magento\Framework\Stdlib\DateTime\Filter\Date
29+
*/
30+
private $dateFilter;
31+
32+
protected function setUp()
33+
{
34+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
35+
36+
$this->localeResolver = $this->objectManager->get(\Magento\Framework\Locale\ResolverInterface::class);
37+
38+
$this->localeDate = $this->objectManager->get(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class, [
39+
'localeResolver' => $this->localeResolver
40+
]);
41+
42+
$this->dateFilter = $this->objectManager->get(\Magento\Framework\Stdlib\DateTime\Filter\Date::class, [
43+
'localeDate' => $this->localeDate
44+
]);
45+
}
46+
47+
/**
48+
* @param string $inputData
49+
* @param string $expectedDate
50+
*
51+
* @dataProvider filterDataProvider
52+
*/
53+
public function testFilter($inputData, $expectedDate)
54+
{
55+
$this->markTestSkipped(
56+
'Input data not realistic with actual request payload from admin UI. See MAGETWO-59810'
57+
);
58+
$this->assertEquals($expectedDate, $this->dateFilter->filter($inputData));
59+
}
60+
61+
/**
62+
* @return array
63+
*/
64+
public function filterDataProvider()
65+
{
66+
return [
67+
['2000-01-01', '2000-01-01'],
68+
['2014-03-30T02:30:00', '2014-03-30'],
69+
['12/31/2000', '2000-12-31']
70+
];
71+
}
72+
73+
/**
74+
* @param string $locale
75+
* @param string $inputData
76+
* @param string $expectedDate
77+
*
78+
* @dataProvider localeDateFilterProvider
79+
* @return void
80+
*/
81+
public function testLocaleDateFilter($locale, $inputData, $expectedDate)
82+
{
83+
$this->localeResolver->setLocale($locale);
84+
$this->assertEquals($expectedDate, $this->dateFilter->filter($inputData));
85+
}
86+
87+
/**
88+
* @return array
89+
*/
90+
public function localeDateFilterProvider()
91+
{
92+
return [
93+
['en_US', '01/02/2010', '2010-01-02'],
94+
['fr_FR', '01/02/2010', '2010-02-01'],
95+
['de_DE', '01/02/2010', '2010-02-01'],
96+
];
97+
}
98+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento\Framework\Stdlib\DateTime\Filter;
7+
8+
use Magento\TestFramework\ObjectManager;
9+
10+
class DateTimeTest extends \PHPUnit\Framework\TestCase
11+
{
12+
/**
13+
* @var ObjectManager
14+
*/
15+
private $objectManager;
16+
17+
/**
18+
* @var \Magento\Framework\Locale\ResolverInterface
19+
*/
20+
private $localeResolver;
21+
22+
/**
23+
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface
24+
*/
25+
private $localeDate;
26+
27+
/**
28+
* @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime
29+
*/
30+
private $dateTimeFilter;
31+
32+
protected function setUp()
33+
{
34+
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
35+
36+
$this->localeResolver = $this->objectManager->get(\Magento\Framework\Locale\ResolverInterface::class);
37+
38+
$this->localeDate = $this->objectManager->get(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class, [
39+
'localeResolver' => $this->localeResolver
40+
]);
41+
42+
$this->dateTimeFilter = $this->objectManager->get(\Magento\Framework\Stdlib\DateTime\Filter\DateTime::class, [
43+
'localeDate' => $this->localeDate
44+
]);
45+
}
46+
47+
/**
48+
* @param string $locale
49+
* @param string $inputData
50+
* @param string $expectedDate
51+
*
52+
* @dataProvider localeDatetimeFilterProvider
53+
* @return void
54+
*/
55+
public function testLocaleDatetimeFilter($locale, $inputData, $expectedDate)
56+
{
57+
$this->localeResolver->setLocale($locale);
58+
$this->assertEquals($expectedDate, $this->dateTimeFilter->filter($inputData));
59+
}
60+
61+
/**
62+
* @return array
63+
*/
64+
public function localeDatetimeFilterProvider()
65+
{
66+
return [
67+
['en_US', '01/02/2010 3:30pm', '2010-01-02 15:30:00'],
68+
['en_US', '01/02/2010 1:00am', '2010-01-02 01:00:00'],
69+
['en_US', '01/02/2010 01:00am', '2010-01-02 01:00:00'],
70+
['fr_FR', '01/02/2010 15:30', '2010-02-01 15:30:00'],
71+
['fr_FR', '01/02/2010 1:00', '2010-02-01 01:00:00'],
72+
['fr_FR', '01/02/2010 01:00', '2010-02-01 01:00:00'],
73+
['de_DE', '01/02/2010 15:30', '2010-02-01 15:30:00'],
74+
['en_US', '2017-09-01T15:30:00.000Z', '2017-09-01 15:30:00'],
75+
['fr_FR', '2017-09-01T15:30:00.000Z', '2017-09-01 15:30:00'],
76+
];
77+
}
78+
}

lib/internal/Magento/Framework/Stdlib/DateTime/Filter/Date.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function __construct(TimezoneInterface $localeDate)
6363
public function filter($value)
6464
{
6565
try {
66-
$value = $this->_localeDate->date($value, null, false);
66+
$value = $this->_localeDate->date($value, null, false, false);
6767
return $value->format('Y-m-d');
6868
} catch (\Exception $e) {
6969
throw new \Exception("Invalid input date format '$value'");

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,6 @@ public function getDateTimeFormat($type)
151151

152152
/**
153153
* {@inheritdoc}
154-
* @SuppressWarnings(PHPMD.NPathComplexity)
155154
*/
156155
public function date($date = null, $locale = null, $useTimezone = true, $includeTime = true)
157156
{

lib/internal/Magento/Framework/Stdlib/Test/Unit/DateTime/TimezoneTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,26 @@ public function testDateIncludeTime($date, $locale, $includeTime, $expectedTimes
9191
public function dateIncludeTimeDataProvider()
9292
{
9393
return [
94-
'Parse date without time' => [
94+
'Parse d/m/y date without time' => [
9595
'19/05/2017', // date
9696
'ar_KW', // locale
9797
false, // include time
9898
1495170000 // expected timestamp
9999
],
100-
'Parse date with time' => [
101-
'05/19/2017 00:01 am', // date
100+
'Parse d/m/y date with time' => [
101+
'19/05/2017 00:01 صباحاً', // datetime (00:01 am)
102+
'ar_KW', // locale
103+
true, // include time
104+
1495170060 // expected timestamp
105+
],
106+
'Parse m/d/y date without time' => [
107+
'05/19/2017', // date
108+
'en_US', // locale
109+
false, // include time
110+
1495170000 // expected timestamp
111+
],
112+
'Parse m/d/y date with time' => [
113+
'05/19/2017 00:01 am', // datetime
102114
'en_US', // locale
103115
true, // include time
104116
1495170060 // expected timestamp

0 commit comments

Comments
 (0)