Skip to content

Commit 9c1568e

Browse files
committed
Merge remote-tracking branch 'troll/MAGETWO-70327' into PRS
2 parents dd4db31 + cde9d7d commit 9c1568e

File tree

7 files changed

+54
-101
lines changed

7 files changed

+54
-101
lines changed

app/code/Magento/Braintree/Test/Unit/Ui/Component/Report/Filters/Type/DateRangeTest.php

Lines changed: 12 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,14 @@ protected function setUp()
6969
->disableOriginalConstructor()
7070
->getMock();
7171

72-
$this->dataProviderMock = $this->getMockForAbstractClass(DataProviderInterface::class);
73-
7472
$this->contextMock->expects($this->any())
7573
->method('getNamespace')
7674
->willReturn(DateRange::NAME);
7775
$this->contextMock->expects($this->any())
7876
->method('addComponentDefinition')
7977
->with(DateRange::NAME, ['extends' => DateRange::NAME]);
8078

81-
$this->contextMock->expects($this->any())
82-
->method('getDataProvider')
83-
->willReturn($this->dataProviderMock);
79+
$this->dataProviderMock = $this->getMockForAbstractClass(DataProviderInterface::class);
8480
}
8581

8682
/**
@@ -95,16 +91,21 @@ protected function setUp()
9591
*/
9692
public function testPrepare($name, $filterData, $expectedCondition)
9793
{
98-
$this->contextMock->expects($this->any())
99-
->method('getFiltersParams')
100-
->willReturn($filterData);
101-
94+
/** @var FormDate PHPUnit_Framework_MockObject_MockObject|$uiComponent */
10295
$uiComponent = $this->getMockBuilder(FormDate::class)->disableOriginalConstructor()->getMock();
10396

10497
$uiComponent->expects($this->any())
10598
->method('getContext')
10699
->willReturn($this->contextMock);
107100

101+
$this->contextMock->expects($this->any())
102+
->method('getFiltersParams')
103+
->willReturn($filterData);
104+
105+
$this->contextMock->expects($this->any())
106+
->method('getDataProvider')
107+
->willReturn($this->dataProviderMock);
108+
108109
if ($expectedCondition !== null) {
109110
if (is_string($filterData[$name])) {
110111
$uiComponent->expects(static::once())
@@ -115,11 +116,11 @@ public function testPrepare($name, $filterData, $expectedCondition)
115116
$uiComponent->method('convertDate')
116117
->willReturnMap([
117118
[
118-
$filterData[$name]['from'],
119+
$filterData[$name]['from'], 0, 0, 0, true,
119120
new \DateTime($filterData[$name]['from'], new \DateTimeZone('UTC'))
120121
],
121122
[
122-
$filterData[$name]['to'],
123+
$filterData[$name]['to'], 23, 59, 59, true,
123124
new \DateTime($filterData[$name]['to'] . ' 23:59:00', new \DateTimeZone('UTC'))
124125
],
125126
]);
@@ -158,23 +159,6 @@ public function testPrepare($name, $filterData, $expectedCondition)
158159
->with($filterMock);
159160
break;
160161
}
161-
} else {
162-
$uiComponent->method('convertDate')
163-
->willReturnMap([
164-
[
165-
$filterData[$name]['from'],
166-
new \DateTime($filterData[$name]['from'], new \DateTimeZone('UTC'))
167-
],
168-
[
169-
$filterData[$name]['to'],
170-
new \DateTime($filterData[$name]['to'] . ' 23:59:00', new \DateTimeZone('UTC'))
171-
],
172-
]);
173-
174-
$filterMock = $this->getFilterMockWithoutExpectedCondition();
175-
$this->dataProviderMock->expects(static::exactly(2))
176-
->method('addFilter')
177-
->with($filterMock);
178162
}
179163

180164
$this->uiComponentFactory->expects($this->any())
@@ -226,31 +210,6 @@ private function getFilterMock($name, $expectedType, $expectedDate, &$i)
226210
return $filterMock;
227211
}
228212

229-
/**
230-
* Gets Filter mock without expected condition
231-
*
232-
* @return Filter|\PHPUnit_Framework_MockObject_MockObject
233-
*/
234-
private function getFilterMockWithoutExpectedCondition()
235-
{
236-
$this->filterBuilderMock->expects(static::exactly(2))
237-
->method('setConditionType')
238-
->willReturnSelf();
239-
$this->filterBuilderMock->expects(static::exactly(2))
240-
->method('setField')
241-
->willReturnSelf();
242-
$this->filterBuilderMock->expects(static::exactly(2))
243-
->method('setValue')
244-
->willReturnSelf();
245-
246-
$filterMock = $this->getMock(Filter::class);
247-
$this->filterBuilderMock->expects(static::exactly(2))
248-
->method('create')
249-
->willReturn($filterMock);
250-
251-
return $filterMock;
252-
}
253-
254213
/**
255214
* @return array
256215
*/

app/code/Magento/Customer/view/adminhtml/ui_component/customer_listing.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@
230230
<settings>
231231
<timezone>false</timezone>
232232
<dateFormat>MMM d, y</dateFormat>
233-
<skipTime>true</skipTime>
233+
<skipTimeZoneConversion>true</skipTimeZoneConversion>
234234
<filter>dateRange</filter>
235235
<dataType>date</dataType>
236236
<label translate="true">Date of Birth</label>

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,26 +79,30 @@ protected function applyFilter()
7979
}
8080

8181
if (is_array($value)) {
82-
$dateFrom = null;
83-
$dateTo = null;
84-
8582
if (isset($value['from'])) {
86-
$dateFrom = $this->wrappedComponent->convertDate($value['from']);
87-
if ($this->getData('config/skipTime')) {
88-
$dateFrom->setTime(0, 0, 0);
89-
}
90-
$this->applyFilterByType('gteq', $dateFrom);
83+
$this->applyFilterByType(
84+
'gteq',
85+
$this->wrappedComponent->convertDate(
86+
$value['from'],
87+
0,
88+
0,
89+
0,
90+
!$this->getData('config/skipTimeZoneConversion')
91+
)
92+
);
9193
}
9294

9395
if (isset($value['to'])) {
94-
$dateTo = $this->wrappedComponent->convertDate($value['to']);
95-
if ($this->getData('config/skipTime')) {
96-
$dateTo->setTime(0, 0, 0);
97-
}
98-
if ($dateFrom == $dateTo) {
99-
$dateTo->setTime(23, 59, 59);
100-
}
101-
$this->applyFilterByType('lteq', $dateTo);
96+
$this->applyFilterByType(
97+
'lteq',
98+
$this->wrappedComponent->convertDate(
99+
$value['to'],
100+
23,
101+
59,
102+
59,
103+
!$this->getData('config/skipTimeZoneConversion')
104+
)
105+
);
102106
}
103107
} else {
104108
$this->applyFilterByType('eq', $this->wrappedComponent->convertDate($value));

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ class Date extends AbstractDataType
3131
*/
3232
protected $wrappedComponent;
3333

34+
/**
35+
* @var TimezoneInterface
36+
*/
37+
private $localeDate;
38+
3439
/**
3540
* Constructor
3641
*
@@ -97,9 +102,13 @@ public function getComponentName()
97102
* Convert given date to default (UTC) timezone
98103
*
99104
* @param int $date
105+
* @param int $hour
106+
* @param int $minute
107+
* @param int $second
108+
* @param bool $setUtcTimeZone
100109
* @return \DateTime|null
101110
*/
102-
public function convertDate($date)
111+
public function convertDate($date, $hour = 0, $minute = 0, $second = 0, $setUtcTimeZone = true)
103112
{
104113
try {
105114
$dateObj = $this->localeDate->date(
@@ -110,8 +119,11 @@ public function convertDate($date)
110119
$this->getLocale(),
111120
true
112121
);
122+
$dateObj->setTime($hour, $minute, $second);
113123
//convert store date to default date in UTC timezone without DST
114-
$dateObj->setTimezone(new \DateTimeZone('UTC'));
124+
if ($setUtcTimeZone) {
125+
$dateObj->setTimezone(new \DateTimeZone('UTC'));
126+
}
115127
return $dateObj;
116128
} catch (\Exception $e) {
117129
return null;

app/code/Magento/Ui/Test/Unit/Component/Filters/Type/DateTest.php

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -126,30 +126,6 @@ public function testPrepare($name, $filterData, $expectedCondition)
126126

127127
if ($expectedCondition !== null) {
128128
$this->processFilters($name, $filterData, $expectedCondition, $uiComponent);
129-
} else {
130-
$uiComponent->method('convertDate')
131-
->willReturnMap([
132-
[$filterData[$name]['from'], new \DateTime($filterData[$name]['from'])],
133-
[$filterData[$name]['to'], new \DateTime($filterData[$name]['to'] . ' 23:59:59')],
134-
]);
135-
136-
$this->filterBuilderMock->expects(static::exactly(2))
137-
->method('setConditionType')
138-
->willReturnSelf();
139-
$this->filterBuilderMock->expects(static::exactly(2))
140-
->method('setField')
141-
->willReturnSelf();
142-
$this->filterBuilderMock->expects(static::exactly(2))
143-
->method('setValue')
144-
->willReturnSelf();
145-
146-
$filterMock = $this->getMock(Filter::class);
147-
$this->filterBuilderMock->expects(static::exactly(2))
148-
->method('create')
149-
->willReturn($filterMock);
150-
$this->dataProviderMock->expects(static::exactly(2))
151-
->method('addFilter')
152-
->with($filterMock);
153129
}
154130

155131
$this->uiComponentFactory->expects($this->any())
@@ -252,10 +228,12 @@ private function processFilters($name, $filterData, $expectedCondition, $uiCompo
252228
->with($filterData[$name])
253229
->willReturn(new \DateTime($filterData[$name]));
254230
} else {
231+
$from = new \DateTime($filterData[$name]['from']);
232+
$to = new \DateTime($filterData[$name]['to'] . ' 23:59:59');
255233
$uiComponent->method('convertDate')
256234
->willReturnMap([
257-
[$filterData[$name]['from'], new \DateTime($filterData[$name]['from'])],
258-
[$filterData[$name]['to'], new \DateTime($filterData[$name]['to'] . ' 23:59:59')],
235+
[$filterData[$name]['from'], 0, 0, 0, true, $from],
236+
[$filterData[$name]['to'], 23, 59, 59, true, $to],
259237
]);
260238
}
261239

app/code/Magento/Ui/view/base/ui_component/etc/definition.map.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@
128128
<item name="dateFormat" type="string" xsi:type="xpath">settings/dateFormat</item>
129129
<item name="timeFormat" type="string" xsi:type="xpath">settings/timeFormat</item>
130130
<item name="timezone" type="string" xsi:type="xpath">settings/timezone</item>
131-
<item name="skipTime" type="boolean" xsi:type="xpath">settings/skipTime</item>
131+
<item name="skipTimeZoneConversion" type="boolean" xsi:type="xpath">settings/skipTimeZoneConversion</item>
132132
<item name="editor" xsi:type="array">
133133
<item name="editorType" type="string" xsi:type="xpath">settings/editor/editorType</item>
134134
<item name="validation" type="item" xsi:type="converter">settings/editor/validation</item>
@@ -240,7 +240,7 @@
240240
<item name="showsTime" type="boolean" xsi:type="xpath">settings/showsTime</item>
241241
<item name="dateFormat" type="string" xsi:type="xpath">settings/dateFormat</item>
242242
<item name="timeFormat" type="string" xsi:type="xpath">settings/timeFormat</item>
243-
<item name="skipTime" type="string" xsi:type="xpath">settings/skipTime</item>
243+
<item name="skipTimeZoneConversion" type="string" xsi:type="xpath">settings/skipTimeZoneConversion</item>
244244
</item>
245245
</argument>
246246
</schema>

app/code/Magento/Ui/view/base/ui_component/etc/definition/column.xsd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@
9898
</xs:annotation>
9999
</xs:element>
100100
<xs:element name="timeFormat" type="xs:string"/>
101-
<xs:element name="skipTime" type="xs:boolean">
101+
<xs:element name="skipTimeZoneConversion" type="xs:boolean">
102102
<xs:annotation>
103103
<xs:documentation>
104104
For the Date column: If time not important for filtering.

0 commit comments

Comments
 (0)