Skip to content

Commit 9d6c358

Browse files
committed
MC-18195: Order Products Report Interval Date incorrect
1 parent 17183cf commit 9d6c358

File tree

3 files changed

+31
-39
lines changed

3 files changed

+31
-39
lines changed

app/code/Magento/Reports/Block/Adminhtml/Grid.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,8 @@ protected function _prepareCollection()
170170
* Validate from and to date
171171
*/
172172
try {
173-
$from = $this->_localeDate->date($this->getFilter('report_from'), null, false, false);
174-
$to = $this->_localeDate->date($this->getFilter('report_to'), null, false, false);
175-
173+
$from = $this->_localeDate->date($this->getFilter('report_from'), null, true, false);
174+
$to = $this->_localeDate->date($this->getFilter('report_to'), null, true, false);
176175
$collection->setInterval($from, $to);
177176
} catch (\Exception $e) {
178177
$this->_errors[] = __('Invalid date specified');

app/code/Magento/Reports/Model/ResourceModel/Report/Collection.php

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,14 @@ class Collection extends \Magento\Framework\Data\Collection
2222
/**
2323
* From value
2424
*
25-
* @var \DateTime
25+
* @var \DateTimeInterface
2626
*/
2727
protected $_from;
2828

2929
/**
3030
* To value
3131
*
32-
* @var \DateTime
32+
* @var \DateTimeInterface
3333
*/
3434
protected $_to;
3535

@@ -125,8 +125,8 @@ public function setPeriod($period)
125125
*/
126126
public function setInterval(\DateTimeInterface $fromDate, \DateTimeInterface $toDate)
127127
{
128-
$this->_from = new \DateTime($fromDate->format('Y-m-d'), $fromDate->getTimezone());
129-
$this->_to = new \DateTime($toDate->format('Y-m-d'), $toDate->getTimezone());
128+
$this->_from = $fromDate;
129+
$this->_to = $toDate;
130130

131131
return $this;
132132
}
@@ -143,8 +143,8 @@ protected function _getIntervals()
143143
if (!$this->_from && !$this->_to) {
144144
return $this->_intervals;
145145
}
146-
$dateStart = $this->_from;
147-
$dateEnd = $this->_to;
146+
$dateStart = new \DateTime($this->_from->format('Y-m-d'), $this->_from->getTimezone());
147+
$dateEnd = new \DateTime($this->_to->format('Y-m-d'), $this->_to->getTimezone());
148148

149149
$firstInterval = true;
150150
while ($dateStart <= $dateEnd) {
@@ -179,11 +179,7 @@ protected function _getIntervals()
179179
protected function _getDayInterval(\DateTime $dateStart)
180180
{
181181
$interval = [
182-
'period' => $this->_localeDate->formatDateTime(
183-
$dateStart,
184-
\IntlDateFormatter::SHORT,
185-
\IntlDateFormatter::NONE
186-
),
182+
'period' => $this->_localeDate->formatDate($dateStart, \IntlDateFormatter::SHORT),
187183
'start' => $this->_localeDate->convertConfigTimeToUtc($dateStart->format('Y-m-d 00:00:00')),
188184
'end' => $this->_localeDate->convertConfigTimeToUtc($dateStart->format('Y-m-d 23:59:59')),
189185
];

app/code/Magento/Reports/Test/Unit/Model/ResourceModel/Report/CollectionTest.php

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,49 +6,49 @@
66

77
namespace Magento\Reports\Test\Unit\Model\ResourceModel\Report;
88

9+
use Magento\Framework\Data\Collection\EntityFactory;
10+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
911
use Magento\Reports\Model\ResourceModel\Report\Collection;
12+
use Magento\Reports\Model\ResourceModel\Report\Collection\Factory as ReportCollectionFactory;
1013

14+
/**
15+
* Class CollectionTest
16+
*
17+
* @covers \Magento\Reports\Model\ResourceModel\Report\Collection
18+
*/
1119
class CollectionTest extends \PHPUnit\Framework\TestCase
1220
{
1321
/**
14-
* @var \Magento\Reports\Model\ResourceModel\Report\Collection
22+
* @var Collection
1523
*/
1624
protected $collection;
1725

1826
/**
19-
* @var \Magento\Framework\Data\Collection\EntityFactory|\PHPUnit_Framework_MockObject_MockObject
27+
* @var EntityFactory|\PHPUnit_Framework_MockObject_MockObject
2028
*/
2129
protected $entityFactoryMock;
2230

2331
/**
24-
* @var \Magento\Framework\Stdlib\DateTime\TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
32+
* @var TimezoneInterface|\PHPUnit_Framework_MockObject_MockObject
2533
*/
2634
protected $timezoneMock;
2735

2836
/**
29-
* @var \Magento\Reports\Model\ResourceModel\Report\Collection\Factory|\PHPUnit_Framework_MockObject_MockObject
37+
* @var ReportCollectionFactory|\PHPUnit_Framework_MockObject_MockObject
3038
*/
3139
protected $factoryMock;
3240

3341
/**
34-
* {@inheritDoc}
42+
* @inheritDoc
3543
*/
3644
protected function setUp()
3745
{
38-
$this->entityFactoryMock = $this->getMockBuilder(\Magento\Framework\Data\Collection\EntityFactory::class)
39-
->disableOriginalConstructor()
40-
->getMock();
41-
$this->timezoneMock = $this->getMockBuilder(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::class)
42-
->getMock();
43-
$this->factoryMock = $this->getMockBuilder(
44-
\Magento\Reports\Model\ResourceModel\Report\Collection\Factory::class
45-
)->disableOriginalConstructor()
46-
->getMock();
47-
48-
$this->timezoneMock
49-
->expects($this->any())
50-
->method('formatDateTime')
51-
->will($this->returnCallback([$this, 'formatDateTime']));
46+
$this->entityFactoryMock = $this->createMock(EntityFactory::class);
47+
$this->timezoneMock = $this->createMock(TimezoneInterface::class);
48+
$this->factoryMock = $this->createMock(ReportCollectionFactory::class);
49+
50+
$this->timezoneMock->method('formatDate')
51+
->will($this->returnCallback([$this, 'formatDate']));
5252

5353
$this->collection = new Collection(
5454
$this->entityFactoryMock,
@@ -131,7 +131,7 @@ public function testGetReports($period, $fromDate, $toDate, $size)
131131
public function testLoadData()
132132
{
133133
$this->assertInstanceOf(
134-
\Magento\Reports\Model\ResourceModel\Report\Collection::class,
134+
Collection::class,
135135
$this->collection->loadData()
136136
);
137137
}
@@ -182,14 +182,11 @@ public function intervalsDataProvider()
182182
}
183183

184184
/**
185+
* @param \DateTimeInterface $dateStart
185186
* @return string
186187
*/
187-
public function formatDateTime()
188+
public function formatDate(\DateTimeInterface $dateStart): string
188189
{
189-
$args = func_get_args();
190-
191-
$dateStart = $args[0];
192-
193190
$formatter = new \IntlDateFormatter(
194191
"en_US",
195192
\IntlDateFormatter::SHORT,

0 commit comments

Comments
 (0)