Skip to content

Commit 25c83ef

Browse files
committed
MAGETWO-34390: Stabilization of replacing Zend_Locale with Native PHP Implementation
1 parent fd6bf75 commit 25c83ef

File tree

14 files changed

+59
-38
lines changed

14 files changed

+59
-38
lines changed

app/code/Magento/Backend/Block/Widget/Grid/Column/Filter/Datetime.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,7 @@ public function getEscapedValue($index = null)
154154
if ($this->getColumn()->getFilterTime()) {
155155
$value = $this->getValue($index);
156156
if ($value instanceof \DateTime) {
157-
return $value->format(
158-
$this->_localeDate->getDateTimeFormat(
159-
\IntlDateFormatter::SHORT
160-
)
161-
);
157+
return $this->_localeDate->formatDateTime($value);
162158
}
163159
return $value;
164160
}

app/code/Magento/Backend/Block/Widget/Grid/Column/Renderer/Date.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function render(\Magento\Framework\Object $row)
6464
{
6565
if ($data = $row->getData($this->getColumn()->getIndex())) {
6666
$format = $this->_getFormat();
67-
return \IntlDateFormatter::formatObject($this->_localeDate->date($data), $format);
67+
return \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($data)), $format);
6868
}
6969
return $this->getColumn()->getDefault();
7070
}

app/code/Magento/CatalogSearch/Model/Indexer/Fulltext/Action/Full.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -773,19 +773,15 @@ protected function getStoreDate($storeId, $date = null)
773773

774774
$dateObj = new \DateTime();
775775
$dateObj->setTimezone(new \DateTimeZone($timezone));
776-
$format = (new \ResourceBundle(
777-
$this->localeResolver->getLocale(),
778-
'ICUDATA'
779-
))['calendar']['gregorian']['availableFormats']['yMMMd'];
780-
$this->dates[$storeId] = [$dateObj, $format];
776+
$this->dates[$storeId] = $dateObj;
781777

782778
$this->localeResolver->revert();
783779
}
784780

785781
if (!$this->dateTime->isEmptyDate($date)) {
786782
list($dateObj, $format) = $this->dates[$storeId];
787783
/** @var \DateTime $dateObj */
788-
return $dateObj->format($format);
784+
return $this->localeDate->formatDateTime($dateObj, \IntlDateFormatter::MEDIUM, \IntlDateFormatter::NONE);
789785
}
790786

791787
return null;

app/code/Magento/Eav/Model/Entity/Attribute/Frontend/Datetime.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@ public function getValue(\Magento\Framework\Object $object)
3737
{
3838
$data = '';
3939
$value = parent::getValue($object);
40-
$format = $this->_localeDate->getDateFormat(\IntlDateFormatter::MEDIUM);
4140

4241
if ($value) {
43-
$data = \IntlDateFormatter::formatObject($this->_localeDate->date($value), $format);
42+
$data = $this->_localeDate->formatDateTime(
43+
$this->_localeDate->date(new \DateTime($value)),
44+
\IntlDateFormatter::MEDIUM,
45+
\IntlDateFormatter::NONE
46+
);
4447
}
4548

4649
return $data;

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,21 @@ protected function _prepareCollection()
9393
if (!isset($data['report_from'])) {
9494
// getting all reports from 2001 year
9595
$date = new \DateTime('@' . mktime(0, 0, 0, 1, 1, 2001));
96-
$data['report_from'] = $date->format($this->_localeDate->getDateFormat());
96+
$data['report_from'] = $this->_localeDate->formatDateTime(
97+
$date,
98+
\IntlDateFormatter::SHORT,
99+
\IntlDateFormatter::NONE
100+
);
97101
}
98102

99103
if (!isset($data['report_to'])) {
100104
// getting all reports from 2001 year
101105
$date = new \DateTime();
102-
$data['report_to'] = $date->format($this->_localeDate->getDateFormat());
106+
$data['report_to'] = $this->_localeDate->formatDateTime(
107+
$date,
108+
\IntlDateFormatter::SHORT,
109+
\IntlDateFormatter::NONE
110+
);
103111
}
104112

105113
$this->_setFilterValues($data);

app/code/Magento/Reports/Block/Adminhtml/Sales/Grid/Column/Renderer/Date.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,12 @@ public function render(\Magento\Framework\Object $row)
8989
try {
9090
$data = $this->getColumn()->getGmtoffset()
9191
? \IntlDateFormatter::formatObject(
92-
$this->_localeDate->date($data),
92+
$this->_localeDate->date(new \DateTime($data)),
9393
$format
9494
)
9595
: \IntlDateFormatter::formatObject(
9696
$this->_localeDate->date(
97-
$data,
97+
new \DateTime($data),
9898
null,
9999
false
100100
),
@@ -103,12 +103,12 @@ public function render(\Magento\Framework\Object $row)
103103
} catch (\Exception $e) {
104104
$data = $this->getColumn()->getTimezone()
105105
? \IntlDateFormatter::formatObject(
106-
$this->_localeDate->date($data),
106+
$this->_localeDate->date(new \DateTime($data)),
107107
$format
108108
)
109109
: \IntlDateFormatter::formatObject(
110110
$this->_localeDate->date(
111-
$data,
111+
new \DateTime($data),
112112
null,
113113
false
114114
),

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,11 @@ protected function _getIntervals()
169169
protected function _getDayInterval(\DateTime $dateStart)
170170
{
171171
$interval = [
172-
'period' => $dateStart->format($this->_localeDate->getDateFormat()),
172+
'period' => $this->_localeDate->formatDateTime(
173+
$dateStart,
174+
\IntlDateFormatter::SHORT,
175+
\IntlDateFormatter::NONE
176+
),
173177
'start' => $dateStart->format('Y-m-d H:i:s'),
174178
'end' => $dateStart->format('Y-m-d 23:59:59'),
175179
];

app/code/Magento/Sales/Model/AbstractModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ abstract public function getStore();
7373
*/
7474
public function getCreatedAtDate()
7575
{
76-
return $this->_localeDate->date($this->getCreatedAt());
76+
return $this->_localeDate->date(new \DateTime($this->getCreatedAt()));
7777
}
7878

7979
/**

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ public function formatDeliveryDateTime($date, $time)
6565
public function formatDeliveryDate($date)
6666
{
6767
$format = $this->_localeDate->getDateFormat(\IntlDateFormatter::MEDIUM);
68-
return \IntlDateFormatter::formatObject($this->_localeDate->date($date), $format);
68+
return \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($date)), $format);
6969
}
7070

7171
/**
@@ -82,7 +82,7 @@ public function formatDeliveryTime($time, $date = null)
8282
}
8383

8484
$format = $this->_localeDate->getTimeFormat(\IntlDateFormatter::SHORT);
85-
return \IntlDateFormatter::formatObject(new \DateTime($time), $format);
85+
return \IntlDateFormatter::formatObject($this->_localeDate->date(new \DateTime($time)), $format);
8686
}
8787

8888
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ protected function convertValue($value)
134134
protected function convertDate($date, $locale)
135135
{
136136
try {
137-
$dateObj = $this->localeDate->date($date, $locale, false);
137+
$dateObj = $this->localeDate->date(new \DateTime($date), $locale, false);
138138
$dateObj->setTime(0, 0, 0);
139139
//convert store date to default date in UTC timezone without DST
140140
$dateObj->setTimezone(new \DateTimeZone('UTC'));

0 commit comments

Comments
 (0)