Skip to content

Commit a88aa19

Browse files
author
Yu Tang
committed
Merge remote-tracking branch 'mainline/develop' into FearlessKiwis-MAGETWO-32905-Refactor-API-Framework
2 parents bbb24a1 + 7de91b4 commit a88aa19

File tree

279 files changed

+1601
-4870
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

279 files changed

+1601
-4870
lines changed

Diff for: app/bootstrap.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,5 @@
3535
\Magento\Framework\Profiler::applyConfig($_SERVER['MAGE_PROFILER'], BP, !empty($_REQUEST['isAjax']));
3636
}
3737
if (ini_get('date.timezone') == '') {
38-
date_default_timezone_set(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::DEFAULT_TIMEZONE);
38+
date_default_timezone_set('UTC');
3939
}

Diff for: app/code/Magento/AdminNotification/Block/ToolbarEntry.php

+11-6
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,18 @@ public function getLatestUnreadNotifications()
6969
*/
7070
public function formatNotificationDate($dateString)
7171
{
72-
if (date('Ymd') == date('Ymd', strtotime($dateString))) {
73-
return $this->formatTime(
74-
$dateString,
75-
\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT,
76-
false
72+
$date = new \DateTime($dateString);
73+
if ($date == new \DateTime('today')) {
74+
return $this->_localeDate->formatDateTime(
75+
$date,
76+
\IntlDateFormatter::NONE,
77+
\IntlDateFormatter::SHORT
7778
);
7879
}
79-
return $this->formatDate($dateString, \Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_MEDIUM, true);
80+
return $this->_localeDate->formatDateTime(
81+
$date,
82+
\IntlDateFormatter::MEDIUM,
83+
\IntlDateFormatter::MEDIUM
84+
);
8085
}
8186
}

Diff for: app/code/Magento/Backend/App/AbstractAction.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ protected function _processLocaleSettings()
290290
}
291291

292292
if (is_null($this->_getSession()->getLocale())) {
293-
$this->_getSession()->setLocale($this->_localeResolver->getLocaleCode());
293+
$this->_getSession()->setLocale($this->_localeResolver->getLocale());
294294
}
295295

296296
return $this;

Diff for: app/code/Magento/Backend/Block/Dashboard/Graph.php

+18-28
Original file line numberDiff line numberDiff line change
@@ -99,27 +99,19 @@ class Graph extends \Magento\Backend\Block\Dashboard\AbstractDashboard
9999
*/
100100
protected $_dashboardData = null;
101101

102-
/**
103-
* @var \Magento\Framework\Locale\ListsInterface
104-
*/
105-
protected $_localeLists = null;
106-
107102
/**
108103
* @param \Magento\Backend\Block\Template\Context $context
109104
* @param \Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory
110105
* @param \Magento\Backend\Helper\Dashboard\Data $dashboardData
111-
* @param \Magento\Framework\Locale\ListsInterface $localeLists
112106
* @param array $data
113107
*/
114108
public function __construct(
115109
\Magento\Backend\Block\Template\Context $context,
116110
\Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory,
117111
\Magento\Backend\Helper\Dashboard\Data $dashboardData,
118-
\Magento\Framework\Locale\ListsInterface $localeLists,
119112
array $data = []
120113
) {
121114
$this->_dashboardData = $dashboardData;
122-
$this->_localeLists = $localeLists;
123115
parent::__construct($context, $collectionFactory, $data);
124116
}
125117

@@ -213,34 +205,36 @@ public function getChartUrl($directUrl = true)
213205
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
214206
);
215207

208+
/** @var \DateTime $dateStart */
209+
/** @var \DateTime $dateEnd */
216210
list($dateStart, $dateEnd) = $this->_collectionFactory->create()->getDateRange(
217211
$this->getDataHelper()->getParam('period'),
218212
'',
219213
'',
220214
true
221215
);
222216

223-
$dateStart->setTimezone($timezoneLocal);
224-
$dateEnd->setTimezone($timezoneLocal);
217+
$dateStart->setTimezone(new \DateTimeZone($timezoneLocal));
218+
$dateEnd->setTimezone(new \DateTimeZone($timezoneLocal));
225219

226220
$dates = [];
227221
$datas = [];
228222

229-
while ($dateStart->compare($dateEnd) < 0) {
223+
while ($dateStart < $dateEnd) {
230224
switch ($this->getDataHelper()->getParam('period')) {
231225
case '7d':
232226
case '1m':
233-
$d = $dateStart->toString('yyyy-MM-dd');
234-
$dateStart->addDay(1);
227+
$d = $dateStart->format('Y-m-d');
228+
$dateStart->modify('+1 day');
235229
break;
236230
case '1y':
237231
case '2y':
238-
$d = $dateStart->toString('yyyy-MM');
239-
$dateStart->addMonth(1);
232+
$d = $dateStart->format('Y-m');
233+
$dateStart->modify('+1 month');
240234
break;
241235
default:
242-
$d = $dateStart->toString('yyyy-MM-dd HH:00');
243-
$dateStart->addHour(1);
236+
$d = $dateStart->format('Y-m-d H:00');
237+
$dateStart->modify('+1 hour');
244238
}
245239
foreach ($this->getAllSeries() as $index => $serie) {
246240
if (in_array($d, $this->_axisLabels['x'])) {
@@ -393,26 +387,22 @@ public function getChartUrl($directUrl = true)
393387
*/
394388
foreach ($this->_axisLabels[$idx] as $_index => $_label) {
395389
if ($_label != '') {
390+
$period = new \DateTime($_label);
396391
switch ($this->getDataHelper()->getParam('period')) {
397392
case '24h':
398-
$this->_axisLabels[$idx][$_index] = $this->formatTime(
399-
new \Magento\Framework\Stdlib\DateTime\Date($_label, 'yyyy-MM-dd HH:00'),
400-
'short',
401-
false
393+
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime(
394+
$period->setTime($period->format('H'), 0, 0),
395+
\IntlDateFormatter::NONE,
396+
\IntlDateFormatter::SHORT
402397
);
403398
break;
404399
case '7d':
405400
case '1m':
406-
$this->_axisLabels[$idx][$_index] = $this->formatDate(
407-
new \Magento\Framework\Stdlib\DateTime\Date($_label, 'yyyy-MM-dd')
408-
);
401+
$this->_axisLabels[$idx][$_index] = $this->_localeDate->formatDateTime($period);
409402
break;
410403
case '1y':
411404
case '2y':
412-
$formats = $this->_localeLists->getTranslationList('datetime');
413-
$format = isset($formats['yyMM']) ? $formats['yyMM'] : 'MM/yyyy';
414-
$format = str_replace(["yyyy", "yy", "MM"], ["Y", "y", "m"], $format);
415-
$this->_axisLabels[$idx][$_index] = date($format, strtotime($_label));
405+
$this->_axisLabels[$idx][$_index] = date('m/Y', strtotime($_label));
416406
break;
417407
}
418408
} else {

Diff for: app/code/Magento/Backend/Block/Dashboard/Tab/Amounts.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@ class Amounts extends \Magento\Backend\Block\Dashboard\Graph
1717
* @param \Magento\Backend\Block\Template\Context $context
1818
* @param \Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory
1919
* @param \Magento\Backend\Helper\Dashboard\Data $dashboardData
20-
* @param \Magento\Framework\Locale\ListsInterface $localeLists
2120
* @param \Magento\Backend\Helper\Dashboard\Order $dataHelper
2221
* @param array $data
2322
*/
2423
public function __construct(
2524
\Magento\Backend\Block\Template\Context $context,
2625
\Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory,
2726
\Magento\Backend\Helper\Dashboard\Data $dashboardData,
28-
\Magento\Framework\Locale\ListsInterface $localeLists,
2927
\Magento\Backend\Helper\Dashboard\Order $dataHelper,
3028
array $data = []
3129
) {
3230
$this->_dataHelper = $dataHelper;
33-
parent::__construct($context, $collectionFactory, $dashboardData, $localeLists, $data);
31+
parent::__construct($context, $collectionFactory, $dashboardData, $data);
3432
}
3533

3634
/**

Diff for: app/code/Magento/Backend/Block/Dashboard/Tab/Orders.php

+1-3
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,18 @@ class Orders extends \Magento\Backend\Block\Dashboard\Graph
1717
* @param \Magento\Backend\Block\Template\Context $context
1818
* @param \Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory
1919
* @param \Magento\Backend\Helper\Dashboard\Data $dashboardData
20-
* @param \Magento\Framework\Locale\ListsInterface $localeLists
2120
* @param \Magento\Backend\Helper\Dashboard\Order $dataHelper
2221
* @param array $data
2322
*/
2423
public function __construct(
2524
\Magento\Backend\Block\Template\Context $context,
2625
\Magento\Reports\Model\Resource\Order\CollectionFactory $collectionFactory,
2726
\Magento\Backend\Helper\Dashboard\Data $dashboardData,
28-
\Magento\Framework\Locale\ListsInterface $localeLists,
2927
\Magento\Backend\Helper\Dashboard\Order $dataHelper,
3028
array $data = []
3129
) {
3230
$this->_dataHelper = $dataHelper;
33-
parent::__construct($context, $collectionFactory, $dashboardData, $localeLists, $data);
31+
parent::__construct($context, $collectionFactory, $dashboardData, $data);
3432
}
3533

3634
/**

Diff for: app/code/Magento/Backend/Block/Menu.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ public function getCacheKeyInfo()
286286
'admin_top_nav',
287287
$this->getActive(),
288288
$this->_authSession->getUser()->getId(),
289-
$this->_localeResolver->getLocaleCode(),
289+
$this->_localeResolver->getLocale(),
290290
];
291291
// Add additional key parameters if needed
292292
$newCacheKeyInfo = $this->getAdditionalCacheKeyInfo();

Diff for: app/code/Magento/Backend/Block/Page.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function _construct()
5252
public function getLang()
5353
{
5454
if (!$this->hasData('lang')) {
55-
$this->setData('lang', substr($this->_localeResolver->getLocaleCode(), 0, 2));
55+
$this->setData('lang', substr($this->_localeResolver->getLocale(), 0, 2));
5656
}
5757
return $this->getData('lang');
5858
}

Diff for: app/code/Magento/Backend/Block/Page/Locale.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function getLocaleSelect()
8383
->setId('footer_interface_locale')
8484
->setTitle(__('Interface Language'))
8585
->setClass('select locale-switcher-select')
86-
->setValue($this->_localeResolver->getLocale()->__toString())
86+
->setValue($this->_localeResolver->getLocale())
8787
->setOptions($this->_localeLists->getTranslatedOptionLocales())
8888
->getHtml();
8989

Diff for: app/code/Magento/Backend/Block/System/Design/Edit/Tab/General.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function _prepareForm()
9292
]
9393
);
9494

95-
$dateFormat = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
95+
$dateFormat = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
9696
$fieldset->addField(
9797
'date_from',
9898
'date',

Diff for: app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Date.php

+28-41
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
* See COPYING.txt for license details.
55
*/
66

7-
// @codingStandardsIgnoreFile
8-
97
namespace Magento\Backend\Block\Widget\Grid\Column\Filter;
108

119
/**
@@ -21,7 +19,7 @@ class Date extends \Magento\Backend\Block\Widget\Grid\Column\Filter\AbstractFilt
2119
/**
2220
* @var \Magento\Framework\Locale\ResolverInterface
2321
*/
24-
protected $_localeResolver;
22+
protected $localeResolver;
2523

2624
/**
2725
* @param \Magento\Backend\Block\Context $context
@@ -38,7 +36,7 @@ public function __construct(
3836
array $data = []
3937
) {
4038
$this->mathRandom = $mathRandom;
41-
$this->_localeResolver = $localeResolver;
39+
$this->localeResolver = $localeResolver;
4240
parent::__construct($context, $resourceHelper, $data);
4341
}
4442

@@ -48,7 +46,7 @@ public function __construct(
4846
public function getHtml()
4947
{
5048
$htmlId = $this->mathRandom->getUniqueHash($this->_getHtmlId());
51-
$format = $this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT);
49+
$format = $this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT);
5250
$html = '<div class="range" id="' .
5351
$htmlId .
5452
'_range"><div class="range-line date">' .
@@ -87,7 +85,7 @@ public function getHtml()
8785
$this->_getHtmlName() .
8886
'[locale]"' .
8987
' value="' .
90-
$this->_localeResolver->getLocaleCode() .
88+
$this->localeResolver->getLocale() .
9189
'"/>';
9290
$html .= '<script>
9391
require(["jquery", "mage/calendar"], function($){
@@ -126,9 +124,10 @@ public function getHtml()
126124
public function getEscapedValue($index = null)
127125
{
128126
$value = $this->getValue($index);
129-
if ($value instanceof \Zend_Date) {
130-
return $value->toString(
131-
$this->_localeDate->getDateFormat(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::FORMAT_TYPE_SHORT)
127+
if ($value instanceof \DateTime) {
128+
return \IntlDateFormatter::formatObject(
129+
$value,
130+
$this->_localeDate->getDateFormat(\IntlDateFormatter::SHORT)
132131
);
133132
}
134133
return $value;
@@ -142,7 +141,6 @@ public function getValue($index = null)
142141
{
143142
if ($index) {
144143
if ($data = $this->getData('value', 'orig_' . $index)) {
145-
//date('Y-m-d', strtotime($data));
146144
return $data;
147145
}
148146
return null;
@@ -173,11 +171,11 @@ public function setValue($value)
173171
if (isset($value['locale'])) {
174172
if (!empty($value['from'])) {
175173
$value['orig_from'] = $value['from'];
176-
$value['from'] = $this->_convertDate($value['from'], $value['locale']);
174+
$value['from'] = $this->_convertDate($value['from']);
177175
}
178176
if (!empty($value['to'])) {
179177
$value['orig_to'] = $value['to'];
180-
$value['to'] = $this->_convertDate($value['to'], $value['locale']);
178+
$value['to'] = $this->_convertDate($value['to']);
181179
}
182180
}
183181
if (empty($value['from']) && empty($value['to'])) {
@@ -191,36 +189,25 @@ public function setValue($value)
191189
* Convert given date to default (UTC) timezone
192190
*
193191
* @param string $date
194-
* @param string $locale
195-
* @return \Magento\Framework\Stdlib\DateTime\Date|null
192+
* @return \DateTime|null
196193
*/
197-
protected function _convertDate($date, $locale)
194+
protected function _convertDate($date)
198195
{
199-
try {
200-
$dateObj = $this->_localeDate->date(null, null, $locale, false);
201-
202-
//set default timezone for store (admin)
203-
$dateObj->setTimezone(
204-
$this->_scopeConfig->getValue(
205-
$this->_localeDate->getDefaultTimezonePath(),
206-
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
207-
)
208-
);
209-
210-
//set beginning of day
211-
$dateObj->setHour(00);
212-
$dateObj->setMinute(00);
213-
$dateObj->setSecond(00);
214-
215-
//set date with applying timezone of store
216-
$dateObj->set($date, \Zend_Date::DATE_SHORT, $locale);
217-
218-
//convert store date to default date in UTC timezone without DST
219-
$dateObj->setTimezone(\Magento\Framework\Stdlib\DateTime\TimezoneInterface::DEFAULT_TIMEZONE);
220-
221-
return $dateObj;
222-
} catch (\Exception $e) {
223-
return null;
224-
}
196+
$adminTimeZone = new \DateTimeZone(
197+
$this->_scopeConfig->getValue(
198+
$this->_localeDate->getDefaultTimezonePath(),
199+
\Magento\Store\Model\ScopeInterface::SCOPE_STORE
200+
)
201+
);
202+
$formatter = new \IntlDateFormatter(
203+
$this->localeResolver->getLocale(),
204+
\IntlDateFormatter::SHORT,
205+
\IntlDateFormatter::NONE,
206+
$adminTimeZone
207+
);
208+
$simpleRes = new \DateTime('@' . $formatter->parse($date), $adminTimeZone);
209+
$simpleRes->setTime(0, 0, 0);
210+
$simpleRes->setTimezone(new \DateTimeZone('UTC'));
211+
return $simpleRes;
225212
}
226213
}

0 commit comments

Comments
 (0)