Skip to content

Commit a245af3

Browse files
author
Maxim Medinskiy
committed
Merge remote-tracking branch 'origin/MAGETWO-35230' into BUGS
2 parents 0be7be5 + 2f5baca commit a245af3

File tree

9 files changed

+22
-18
lines changed

9 files changed

+22
-18
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,8 @@ protected function _convertDate($date)
205205
\IntlDateFormatter::NONE,
206206
$adminTimeZone
207207
);
208-
$simpleRes = new \DateTime('@' . $formatter->parse($date), $adminTimeZone);
208+
$simpleRes = new \DateTime(null, $adminTimeZone);
209+
$simpleRes->setTimestamp($formatter->parse($date));
209210
$simpleRes->setTime(0, 0, 0);
210211
$simpleRes->setTimezone(new \DateTimeZone('UTC'));
211212
return $simpleRes;

app/code/Magento/Backup/Model/Backup.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ public function load($fileName, $filePath)
152152
'extension' => $this->_helper->getExtensionByType($backupData->getType()),
153153
'display_name' => $this->_helper->nameToDisplayName($backupData->getName()),
154154
'name' => $backupData->getName(),
155-
'date_object' => new \DateTime('@' . $backupData->getTime()),
155+
'date_object' => (new \DateTime())->setTimestamp($backupData->getTime()),
156156
]
157157
);
158158

app/code/Magento/Catalog/Model/Product/Option/Type/Date.php

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function prepareForCart()
165165
$timestamp += 60 * 60 * $value['hour'] + 60 * $value['minute'];
166166
}
167167

168-
$date = new \DateTime('@' . $timestamp);
168+
$date = (new \DateTime())->setTimestamp($timestamp);
169169
$result = $date->format('Y-m-d H:i:s');
170170

171171
// Save date in internal format to avoid locale date bugs
@@ -188,19 +188,22 @@ public function getFormattedOptionValue($optionValue)
188188
{
189189
if ($this->_formattedOptionValue === null) {
190190
if ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE) {
191-
$format = $this->_localeDate->getDateFormat(
192-
\IntlDateFormatter::MEDIUM
191+
$result = $this->_localeDate->formatDateTime(
192+
new \DateTime($optionValue),
193+
\IntlDateFormatter::MEDIUM,
194+
\IntlDateFormatter::NONE
193195
);
194-
$result = \IntlDateFormatter::formatObject(new \DateTime($optionValue), $format);
195196
} elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_DATE_TIME) {
196-
$format = $this->_localeDate->getDateTimeFormat(
197+
$result = $this->_localeDate->formatDateTime(
198+
new \DateTime($optionValue),
199+
\IntlDateFormatter::SHORT,
197200
\IntlDateFormatter::SHORT
198201
);
199-
$result = \IntlDateFormatter::formatObject(new \DateTime($optionValue), $format);
200202
} elseif ($this->getOption()->getType() == \Magento\Catalog\Model\Product\Option::OPTION_TYPE_TIME) {
201-
$result = \IntlDateFormatter::formatObject(
203+
$result = $this->_localeDate->formatDateTime(
202204
new \DateTime($optionValue),
203-
$this->is24hTimeFormat() ? 'H:i' : 'h:i a'
205+
\IntlDateFormatter::NONE,
206+
\IntlDateFormatter::SHORT
204207
);
205208
} else {
206209
$result = $optionValue;

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ protected function _saveProducts()
10861086
$storeIds = [0];
10871087

10881088
if ('datetime' == $attribute->getBackendType() && strtotime($attrValue)) {
1089-
$attrValue = new \DateTime('@' . strtotime($attrValue));
1089+
$attrValue = (new \DateTime())->setTimestamp(strtotime($attrValue));
10901090
$attrValue = $attrValue->format(DateTime::DATETIME_PHP_FORMAT);
10911091
} elseif ($backModel) {
10921092
$attribute->getBackend()->beforeSave($product);

app/code/Magento/CatalogRule/Model/Observer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ public function prepareCatalogProductCollectionPrices(EventObserver $observer)
267267
if ($observer->getEvent()->hasDate()) {
268268
$date = new \DateTime($observer->getEvent()->getDate());
269269
} else {
270-
$date = new \DateTime('@' . $this->_localeDate->scopeTimeStamp($store));
270+
$date = (new \DateTime())->setTimestamp($this->_localeDate->scopeTimeStamp($store));
271271
}
272272

273273
$productIds = [];

app/code/Magento/CustomerImportExport/Model/Import/Address.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ protected function _prepareDataForUpdate(array $rowData)
473473
if ('select' == $attributeParams['type']) {
474474
$value = $attributeParams['options'][strtolower($rowData[$attributeAlias])];
475475
} elseif ('datetime' == $attributeParams['type']) {
476-
$value = new \DateTime('@' . strtotime($rowData[$attributeAlias]));
476+
$value = (new \DateTime())->setTimestamp(strtotime($rowData[$attributeAlias]));
477477
$value = $value->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
478478
} else {
479479
$value = $rowData[$attributeAlias];

app/code/Magento/CustomerImportExport/Model/Import/Customer.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,11 +292,11 @@ protected function _prepareDataForUpdate(array $rowData)
292292
$attributesToSave = [];
293293

294294
// entity table data
295-
$now = new \DateTime('@' . time());
295+
$now = new \DateTime();
296296
if (empty($rowData['created_at'])) {
297297
$createdAt = $now;
298298
} else {
299-
$createdAt = new \DateTime('@' . strtotime($rowData['created_at']));
299+
$createdAt = (new \DateTime())->setTimestamp(strtotime($rowData['created_at']));
300300
}
301301
$entityRow = [
302302
'group_id' => empty($rowData['group_id']) ? self::DEFAULT_GROUP_ID : $rowData['group_id'],
@@ -333,7 +333,7 @@ protected function _prepareDataForUpdate(array $rowData)
333333
if ('select' == $attributeParameters['type']) {
334334
$value = $attributeParameters['options'][strtolower($value)];
335335
} elseif ('datetime' == $attributeParameters['type']) {
336-
$value = new \DateTime('@' . strtotime($value));
336+
$value = (new \DateTime())->setTimestamp(strtotime($value));
337337
$value = $value->format(\Magento\Framework\Stdlib\DateTime::DATETIME_PHP_FORMAT);
338338
} elseif ($backendModel) {
339339
$attribute->getBackend()->beforeSave($this->_customerModel->setData($attributeCode, $value));

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public function formatDate($date)
7171
}
7272
// unix timestamp given - simply instantiate date object
7373
if (is_scalar($date) && preg_match('/^[0-9]+$/', $date)) {
74-
$date = new \DateTime('@' . $date);
74+
$date = (new \DateTime())->setTimestamp($date);
7575
// international format
7676
} elseif (!($date instanceof \DateTime)) {
7777
$date = new \DateTime($date);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ protected function _prepareCollection()
9292

9393
if (!isset($data['report_from'])) {
9494
// getting all reports from 2001 year
95-
$date = new \DateTime('@' . mktime(0, 0, 0, 1, 1, 2001));
95+
$date = (new \DateTime())->setTimestamp(mktime(0, 0, 0, 1, 1, 2001));
9696
$data['report_from'] = $this->_localeDate->formatDateTime(
9797
$date,
9898
\IntlDateFormatter::SHORT,

0 commit comments

Comments
 (0)