Skip to content

Commit ac031cb

Browse files
committed
ACP2E-2738: new fix data conversion impacted by timezone
1 parent d9b069e commit ac031cb

File tree

6 files changed

+90
-36
lines changed

6 files changed

+90
-36
lines changed

app/code/Magento/Fedex/Model/Carrier.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ private function processTrackingDetails($trackInfo): array
15671567
}
15681568

15691569
if ($datetime) {
1570-
$result['shippeddate'] = gmdate('Y-m-d H:i:s', $datetime->getTimestamp());
1570+
$result['shippeddate'] = gmdate('Y-m-d', $datetime->getTimestamp());
15711571
}
15721572
}
15731573

@@ -1586,7 +1586,7 @@ private function processTrackingDetails($trackInfo): array
15861586

15871587
$datetime = $this->getDeliveryDateTime($trackInfo);
15881588
if ($datetime) {
1589-
$result['deliverydate'] = gmdate('Y-m-d H:i:s', $datetime->getTimestamp());
1589+
$result['deliverydate'] = gmdate('Y-m-d', $datetime->getTimestamp());
15901590
$result['deliverytime'] = gmdate('H:i:s', $datetime->getTimestamp());
15911591
}
15921592

@@ -1699,7 +1699,7 @@ private function processTrackDetailsEvents(array $events): array
16991699

17001700
$datetime = $this->parseDate(!empty($event['date']) ? $event['date'] : null);
17011701
if ($datetime) {
1702-
$item['deliverydate'] = gmdate('Y-m-d H:i:s', $datetime->getTimestamp());
1702+
$item['deliverydate'] = gmdate('Y-m-d', $datetime->getTimestamp());
17031703
$item['deliverytime'] = gmdate('H:i:s', $datetime->getTimestamp());
17041704
}
17051705

app/code/Magento/Fedex/Plugin/Block/Tracking/PopupDeliveryDate.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class PopupDeliveryDate
2828
public function afterFormatDeliveryDateTime(Popup $subject, $result, $date, $time)
2929
{
3030
if ($this->getCarrier($subject) === Carrier::CODE) {
31-
$result = $subject->formatDeliveryDate($date);
31+
$result = $subject->formatDeliveryDate($date. ' ' . $time);
3232
}
3333
return $result;
3434
}

app/code/Magento/Fedex/Test/Unit/Model/CarrierTest.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,6 @@ public function testGetTrackingErrorResponse(): void
650650
*/
651651
public function getTrackResponse($shipTimeStamp, $expectedDate, $expectedTime): array
652652
{
653-
$expectedDateTime = ($expectedDate ? date('Y-m-d', strtotime($expectedDate)) : null).'T'.$expectedTime;
654653
$trackResponse = '{"transactionId":"4d37cd0c-f4e8-449f-ac95-d4d3132f0572",
655654
"output":{"completeTrackResults":[{"trackingNumber":"122816215025810","trackResults":[{"trackingNumberInfo":
656655
{"trackingNumber":"122816215025810","trackingNumberUniqueId":"12013~122816215025810~FDEG","carrierCode":"FDXG"},
@@ -662,14 +661,14 @@ public function getTrackResponse($shipTimeStamp, $expectedDate, $expectedTime):
662661
"latestStatusDetail":{"code":"DL","derivedCode":"DL","statusByLocale":"Delivered","description":"Delivered",
663662
"scanLocation":{"city":"Norton","stateOrProvinceCode":"VA","countryCode":"US","residential":false,
664663
"countryName":"United States"}},"dateAndTimes":[{"type":"ACTUAL_DELIVERY","dateTime":
665-
"'.$expectedDateTime.'"},{"type":"ACTUAL_PICKUP","dateTime":"2016-08-01T00:00:00-06:00"},
664+
"'.$expectedDate.'T'.$expectedTime.'"},{"type":"ACTUAL_PICKUP","dateTime":"2016-08-01T00:00:00-06:00"},
666665
{"type":"SHIP","dateTime":"'.$shipTimeStamp.'"}],"availableImages":[{"type":"SIGNATURE_PROOF_OF_DELIVERY"}],
667666
"specialHandlings":[{"type":"DIRECT_SIGNATURE_REQUIRED","description":"Direct Signature Required",
668667
"paymentType":"OTHER"}],"packageDetails":{"packagingDescription":{"type":"YOUR_PACKAGING","description":
669668
"Package"},"physicalPackagingType":"PACKAGE","sequenceNumber":"1","count":"1","weightAndDimensions":
670669
{"weight":[{"value":"21.5","unit":"LB"},{"value":"9.75","unit":"KG"}],"dimensions":[{"length":22,"width":17,
671670
"height":10,"units":"IN"},{"length":55,"width":43,"height":25,"units":"CM"}]},"packageContent":[]},
672-
"shipmentDetails":{"possessionStatus":true},"scanEvents":[{"date":"'.$expectedDateTime.'",
671+
"shipmentDetails":{"possessionStatus":true},"scanEvents":[{"date":"'.$expectedDate.'T'.$expectedTime.'",
673672
"eventType":"DL","eventDescription":"Delivered","exceptionCode":"","exceptionDescription":"","scanLocation":
674673
{"streetLines":[""],"city":"Norton","stateOrProvinceCode":"VA","postalCode":"24273","countryCode":"US",
675674
"residential":false,"countryName":"United States"},"locationType":"DELIVERY_LOCATION","derivedStatusCode":"DL",
@@ -952,27 +951,27 @@ public function shipDateDataProvider(): array
952951
'tracking1' => [
953952
'tracking1',
954953
'shipTimestamp' => '2020-08-15T02:06:35+03:00',
955-
'expectedDate' => '2014-01-09 18:31:00',
954+
'expectedDate' => '2014-01-09',
956955
'18:31:00',
957956
0,
958957
],
959958
'tracking1-again' => [
960959
'tracking1',
961960
'shipTimestamp' => '2014-01-09T02:06:35+03:00',
962-
'expectedDate' => '2014-01-09 18:31:00',
961+
'expectedDate' => '2014-01-09',
963962
'18:31:00',
964963
0,
965964
],
966965
'tracking2' => [
967966
'tracking2',
968967
'shipTimestamp' => '2014-01-09T02:06:35+03:00',
969-
'expectedDate' => '2014-01-09 23:06:35',
968+
'expectedDate' => '2014-01-09',
970969
'23:06:35',
971970
],
972971
'tracking3' => [
973972
'tracking3',
974973
'shipTimestamp' => '2014-01-09T14:06:35',
975-
'expectedDate' => '2014-01-09 18:31:00',
974+
'expectedDate' => '2014-01-09',
976975
'18:31:00',
977976
],
978977
'tracking4' => [

app/code/Magento/Fedex/Test/Unit/Plugin/Block/Tracking/PopupDeliveryDateTest.php

Lines changed: 63 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
*/
2222
class PopupDeliveryDateTest extends TestCase
2323
{
24-
const STUB_CARRIER_CODE_NOT_FEDEX = 'not-fedex';
25-
const STUB_DELIVERY_DATE = '2020-02-02';
26-
const STUB_DELIVERY_TIME = '12:00';
24+
public const STUB_CARRIER_CODE_NOT_FEDEX = 'not-fedex';
25+
public const STUB_DELIVERY_DATE = '2020-02-02';
26+
public const STUB_DELIVERY_TIME = '12:00';
2727

2828
/**
2929
* @var MockObject|PopupDeliveryDate
@@ -68,6 +68,30 @@ public function testAfterFormatDeliveryDateTimeWithFedexCarrier()
6868
$this->executeOriginalMethod();
6969
}
7070

71+
/**
72+
* Test the method with Fedex carrier with timezone impact
73+
* @dataProvider getDates
74+
*/
75+
public function testAfterFormatDeliveryDateTimeWithFedexCarrierWithTimezone(
76+
$date,
77+
$currentTimezone,
78+
$convertedTimezone,
79+
$expected
80+
) {
81+
$this->trackingStatusMock->expects($this::once())
82+
->method('getCarrier')
83+
->willReturn(Carrier::CODE);
84+
85+
$date = new \DateTime($date, new \DateTimeZone($currentTimezone));
86+
$date->setTimezone(new \DateTimeZone($convertedTimezone));
87+
$this->subjectMock->expects($this->once())->method('formatDeliveryDate')
88+
->willReturn($date->format('Y-m-d'));
89+
90+
$result = $this->executeOriginalMethodWithTimezone();
91+
92+
$this->assertEquals($expected, $result);
93+
}
94+
7195
/**
7296
* Test the method with a different carrier
7397
*/
@@ -119,4 +143,40 @@ private function executeOriginalMethod()
119143
self::STUB_DELIVERY_TIME
120144
);
121145
}
146+
147+
/**
148+
* Run plugin's original method taking into account timezone
149+
*/
150+
private function executeOriginalMethodWithTimezone()
151+
{
152+
return $this->plugin->afterFormatDeliveryDateTime(
153+
$this->subjectMock,
154+
'Test Result',
155+
self::STUB_DELIVERY_DATE,
156+
'00:00:00'
157+
);
158+
}
159+
160+
/**
161+
* Data provider for testAfterFormatDeliveryDateTimeWithFedexCarrierWithTimezone
162+
*
163+
* @return array[]
164+
*/
165+
public function getDates(): array
166+
{
167+
return [
168+
'same day' => [
169+
'date' => '2024-01-07 06:00:00',
170+
'current_timezone' => 'US/Eastern',
171+
'converted_timezone' => 'America/Chicago',
172+
'expected' => '2024-01-07'
173+
],
174+
'previous day' => [
175+
'date' => '2024-01-07 00:00:00',
176+
'current_timezone' => 'US/Eastern',
177+
'converted_timezone' => 'America/Chicago',
178+
'expected' => '2024-01-06'
179+
]
180+
];
181+
}
122182
}

app/code/Magento/Shipping/Block/Tracking/Popup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function formatDeliveryDate($date)
9292
public function formatDeliveryTime($time, $date = null)
9393
{
9494
if (!empty($date)) {
95-
$time = $date;
95+
$time = $date . ' ' . $time;
9696
}
9797

9898
$format = $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT);

app/code/Magento/Shipping/view/frontend/templates/tracking/progress.phtml

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,40 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
/**
8-
* @var \Magento\Framework\View\Element\Template $block
9-
* @var \Magento\Framework\Escaper $escaper
10-
*/
7+
/** @var $block \Magento\Framework\View\Element\Template */
118
$parentBlock = $block->getParentBlock();
129
$track = $block->getData('track');
1310
?>
1411
<div class="table-wrapper">
15-
<table class="data table order tracking"
16-
id="track-history-table-<?= $escaper->escapeHtml($track->getTracking()) ?>">
17-
<caption class="table-caption"><?= $escaper->escapeHtml(__('Track history')) ?></caption>
12+
<table class="data table order tracking" id="track-history-table-<?= $block->escapeHtml($track->getTracking()) ?>">
13+
<caption class="table-caption"><?= $block->escapeHtml(__('Track history')) ?></caption>
1814
<thead>
1915
<tr>
20-
<th class="col location" scope="col"><?= $escaper->escapeHtml(__('Location')) ?></th>
21-
<th class="col date" scope="col"><?= $escaper->escapeHtml(__('Date')) ?></th>
22-
<th class="col time" scope="col"><?= $escaper->escapeHtml(__('Local Time')) ?></th>
23-
<th class="col description" scope="col"><?= $escaper->escapeHtml(__('Description')) ?></th>
16+
<th class="col location" scope="col"><?= $block->escapeHtml(__('Location')) ?></th>
17+
<th class="col date" scope="col"><?= $block->escapeHtml(__('Date')) ?></th>
18+
<th class="col time" scope="col"><?= $block->escapeHtml(__('Local Time')) ?></th>
19+
<th class="col description" scope="col"><?= $block->escapeHtml(__('Description')) ?></th>
2420
</tr>
2521
</thead>
2622
<tbody>
27-
<?php foreach ($track->getProgressdetail() as $detail): ?>
28-
<?php $detailDate = (!empty($detail['deliverydate'])?
29-
$parentBlock->formatDeliveryDate($detail['deliverydate']) :
23+
<?php foreach ($track->getProgressdetail() as $detail) : ?>
24+
<?php $detailDate = (!empty($detail['deliverydate']) ?
25+
$parentBlock->formatDeliveryDate($detail['deliverydate'] . ' ' . $detail['deliverytime']) :
3026
''); ?>
3127
<?php $detailTime = (!empty($detail['deliverytime']) ?
3228
$parentBlock->formatDeliveryTime($detail['deliverytime'], $detail['deliverydate']) :
3329
''); ?>
3430
<tr>
35-
<td data-th="<?= $escaper->escapeHtml(__('Location')) ?>" class="col location">
36-
<?= (!empty($detail['deliverylocation']) ?
37-
$escaper->escapeHtml($detail['deliverylocation']) : '') ?>
31+
<td data-th="<?= $block->escapeHtml(__('Location')) ?>" class="col location">
32+
<?= (!empty($detail['deliverylocation']) ? $block->escapeHtml($detail['deliverylocation']) : '') ?>
3833
</td>
39-
<td data-th="<?= $escaper->escapeHtml(__('Date')) ?>" class="col date">
34+
<td data-th="<?= $block->escapeHtml(__('Date')) ?>" class="col date">
4035
<?= /* @noEscape */ $detailDate ?>
4136
</td>
42-
<td data-th="<?= $escaper->escapeHtml(__('Local Time')) ?>" class="col time">
37+
<td data-th="<?= $block->escapeHtml(__('Local Time')) ?>" class="col time">
4338
<?= /* @noEscape */ $detailTime ?></td>
44-
<td data-th="<?= $escaper->escapeHtml(__('Description')) ?>" class="col description">
45-
<?= (!empty($detail['activity']) ? $escaper->escapeHtml($detail['activity']) : '') ?>
39+
<td data-th="<?= $block->escapeHtml(__('Description')) ?>" class="col description">
40+
<?= (!empty($detail['activity']) ? $block->escapeHtml($detail['activity']) : '') ?>
4641
</td>
4742
</tr>
4843
<?php endforeach; ?>

0 commit comments

Comments
 (0)