From 26a78674e4325392e22ac8ce26b197056a9b185f Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Tue, 23 May 2023 21:46:53 +0100 Subject: [PATCH 1/3] rebased to main --- README.md | 1 - .../Block/Customer/Edit/Tab/View.php | 16 ++++--- app/code/core/Mage/Core/Block/Abstract.php | 1 + app/code/core/Mage/Core/Helper/Data.php | 43 +++++++++++++------ 4 files changed, 41 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 4732c0fb36c..8cec29536af 100644 --- a/README.md +++ b/README.md @@ -226,7 +226,6 @@ Do not use 20.x.x if you need IE support. - removed IE conditional comments, IE styles, IE scripts and IE eot files ([#1073](https://github.com/OpenMage/magento-lts/pull/1073)) - removed frontend default themes (default, modern, iphone, german, french, blank, blue) ([#1600](https://github.com/OpenMage/magento-lts/pull/1600)) -- fixed incorrect datetime in customer block (`$useTimezone` parameter) ([#1525](https://github.com/OpenMage/magento-lts/pull/1525)) - added redis as a valid option for `global/session_save` ([#1513](https://github.com/OpenMage/magento-lts/pull/1513)) - reduce needless saves by avoiding setting `_hasDataChanges` flag ([#2066](https://github.com/OpenMage/magento-lts/pull/2066)) - removed support for `global/sales/old_fields_map` defined in XML ([#921](https://github.com/OpenMage/magento-lts/pull/921)) diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php index 5f8a82bb9b9..e23cc88089e 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php @@ -82,15 +82,17 @@ public function getCreateDate() */ public function getStoreCreateDate() { - if (!$this->getCustomer()->getCreatedAt()) { + $date = $this->getCustomer()->getCreatedAt(); + if (!$date) { return null; } - $date = Mage::app()->getLocale()->storeDate( - $this->getCustomer()->getStoreId(), - $this->getCustomer()->getCreatedAtTimestamp(), - true + + return $this->_getCoreHelper()->formatTimezoneDate( + $date, + Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, + true, + false ); - return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true); } public function getStoreCreateDateTimezone() @@ -107,7 +109,7 @@ public function getStoreCreateDateTimezone() public function getLastLoginDate() { return ($date = $this->getCustomerLog()->getLoginAtTimestamp()) - ? $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false) + ? Mage::helper('core')->formatTimezoneDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false) : Mage::helper('customer')->__('Never'); } diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index 35a805a145b..1f190449118 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -480,6 +480,7 @@ public function setChild($alias, $block) public function unsetChild($alias) { if (isset($this->_children[$alias])) { + /** @var Mage_Core_Block_Abstract $block */ $block = $this->_children[$alias]; $name = $block->getNameInLayout(); unset($this->_children[$alias]); diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index 4928c699309..d072be6504b 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -146,7 +146,7 @@ public function formatPrice($price, $includeContainer = true) /** * Format date using current locale options and time zone. * - * @param string|Zend_Date|null $date If empty, return current datetime. + * @param string|Zend_Date|int|null $date If empty, return current local datetime. * @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants * @param bool $showTime Whether to include time * @param bool $useTimezone Convert to local datetime? @@ -154,25 +154,44 @@ public function formatPrice($price, $includeContainer = true) */ public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false, $useTimezone = true) { + return $this->formatTimezoneDate($date, $format, $showTime); + } + + /** + * Format date using current locale options and time zone. + * + * @param string|Zend_Date|null $date If empty, return current datetime. + * @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants + * @param bool $showTime Whether to include time + * @param bool $useTimezone Convert to local datetime? + * @return string + */ + public function formatTimezoneDate( + $date = null, + string $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, + bool $showTime = false, + bool $useTimezone = true + ) { if (!in_array($format, $this->_allowedFormats, true)) { return $date; } + + if ($showTime) { + $format = Mage::app()->getLocale()->getDateTimeFormat($format); + } else { + $format = Mage::app()->getLocale()->getDateFormat($format); + } + + $locale = Mage::app()->getLocale(); if (empty($date)) { - $date = Mage::app()->getLocale()->date(Mage::getSingleton('core/date')->gmtTimestamp(), null, null, $useTimezone); + $date = $locale->date(Mage::getSingleton('core/date')->gmtTimestamp(), null, null, $useTimezone); } elseif (is_int($date)) { - $date = Mage::app()->getLocale()->date($date, null, null, $useTimezone); + $date = $locale->date($date, null, null, $useTimezone); } elseif (!$date instanceof Zend_Date) { - if ($time = strtotime($date)) { - $date = Mage::app()->getLocale()->date($time, null, null, $useTimezone); - } else { - return ''; - } + return ''; } - $format = $showTime - ? Mage::app()->getLocale()->getDateTimeFormat($format) - : Mage::app()->getLocale()->getDateFormat($format); - + $format = $showTime ? $locale->getDateTimeFormat($format) : $locale->getDateFormat($format); return $date->toString($format); } From bb2394418932ae6c07e88e429311c3dae8d0f5b4 Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Tue, 19 Sep 2023 17:07:48 +0100 Subject: [PATCH 2/3] not using deprecated method --- app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php index 764d2a97a37..44774e77d4f 100644 --- a/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php +++ b/app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php @@ -87,7 +87,7 @@ public function getStoreCreateDate() return null; } - return $this->_getCoreHelper()->formatTimezoneDate( + return Mage::helper('core')->formatTimezoneDate( $date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, From ad1e26767251587d9df5e0c80268867ff84e383f Mon Sep 17 00:00:00 2001 From: Fabrizio Balliano Date: Tue, 19 Sep 2023 17:11:38 +0100 Subject: [PATCH 3/3] I do not love this formatting, but it is used in other parts of this file --- app/code/core/Mage/Core/Helper/Data.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index d11545b237b..349a2ff6011 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -146,10 +146,10 @@ public function formatPrice($price, $includeContainer = true) /** * Format date using current locale options and time zone. * - * @param string|Zend_Date|int|null $date If empty, return current local datetime. - * @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants - * @param bool $showTime Whether to include time - * @param bool $useTimezone Convert to local datetime? + * @param string|Zend_Date|int|null $date If empty, return current local datetime. + * @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants + * @param bool $showTime Whether to include time + * @param bool $useTimezone Convert to local datetime? * @return string */ public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false, $useTimezone = true) @@ -160,10 +160,10 @@ public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMA /** * Format date using current locale options and time zone. * - * @param string|Zend_Date|null $date If empty, return current datetime. - * @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants - * @param bool $showTime Whether to include time - * @param bool $useTimezone Convert to local datetime? + * @param string|Zend_Date|null $date If empty, return current datetime. + * @param string $format See Mage_Core_Model_Locale::FORMAT_TYPE_* constants + * @param bool $showTime Whether to include time + * @param bool $useTimezone Convert to local datetime? * @return string */ public function formatTimezoneDate(