From e19a8dec9eeb41bcbadf36f5ee4ff85d51495fa5 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Mon, 26 Dec 2022 22:00:17 +0100 Subject: [PATCH 1/3] Replacement for #1525 --- .../Block/Customer/Edit/Tab/View.php | 12 ++++--- app/code/core/Mage/Core/Block/Abstract.php | 1 + app/code/core/Mage/Core/Helper/Data.php | 31 ++++++++++++++----- 3 files changed, 32 insertions(+), 12 deletions(-) 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 eaaa09052b0..810a125f3c6 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 @@ -79,13 +79,15 @@ public function getCustomerLog() */ public function getCreateDate() { - if (!$this->getCustomer()->getCreatedAt()) { + $date = $this->getCustomer()->getCreatedAt(); + if (!$date) { return null; } - return $this->_getCoreHelper()->formatDate( - $this->getCustomer()->getCreatedAt(), + return $this->_getCoreHelper()->formatTimezoneDate( + $date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, - true + true, + false ); } @@ -120,7 +122,7 @@ public function getLastLoginDate() { $date = $this->getCustomerLog()->getLoginAtTimestamp(); if ($date) { - return Mage::helper('core')->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true); + return Mage::helper('core')->formatTimezoneDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false); } return 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 13845e418f2..2a7eccb0965 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -487,6 +487,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 2c78cd55116..69d6df4cd46 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -153,23 +153,40 @@ public function formatPrice($price, $includeContainer = true) /** * Format date using current locale options and time zone. * - * @param string|Zend_Date|null $date + * @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 * @return string */ public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false) + { + 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, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false, $useTimezone = true) { if (!in_array($format, $this->_allowedFormats, true)) { return $date; } - if (!($date instanceof Zend_Date) && $date && !strtotime($date)) { - return ''; - } - if (is_null($date)) { - $date = Mage::app()->getLocale()->date(Mage::getSingleton('core/date')->gmtTimestamp(), null, null); + if (empty($date)) { + $date = Mage::app()->getLocale()->date(Mage::getSingleton('core/date')->gmtTimestamp(), null, null, $useTimezone); + } elseif (is_int($date)) { + $date = Mage::app()->getLocale()->date($date, null, null, $useTimezone); } elseif (!$date instanceof Zend_Date) { - $date = Mage::app()->getLocale()->date(strtotime($date), null, null); + if ($time = strtotime($date)) { + $date = Mage::app()->getLocale()->date($time, null, null, $useTimezone); + } else { + return ''; + } } if ($showTime) { From 70d7c3289f2f975b6666c436421a4ae338cd579b Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Mon, 26 Dec 2022 22:03:22 +0100 Subject: [PATCH 2/3] Updated method --- README.md | 1 - app/code/core/Mage/Core/Helper/Data.php | 30 +++++++++++++------------ 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 53a77f46240..a93c330729d 100644 --- a/README.md +++ b/README.md @@ -117,7 +117,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/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index 69d6df4cd46..725ca8f4f50 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -172,29 +172,31 @@ public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMA * @param bool $useTimezone Convert to local datetime? * @return string */ - public function formatTimezoneDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false, $useTimezone = true) - { + 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; } + + $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 ''; + $time = strtotime($date); + if ($time) { + $date = $locale->date($time, null, null, $useTimezone); } + return ''; } - if ($showTime) { - $format = Mage::app()->getLocale()->getDateTimeFormat($format); - } else { - $format = Mage::app()->getLocale()->getDateFormat($format); - } - + $format = $showTime ? $locale->getDateTimeFormat($format) : $locale->getDateFormat($format); return $date->toString($format); } From 281d330ad74b13476d122f8fe847c8453e54b179 Mon Sep 17 00:00:00 2001 From: sv3n Date: Wed, 28 Dec 2022 04:40:15 +0100 Subject: [PATCH 3/3] Update app/code/core/Mage/Core/Helper/Data.php Co-authored-by: Ng Kiat Siong --- app/code/core/Mage/Core/Helper/Data.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index 725ca8f4f50..e7aa8b1b392 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -153,7 +153,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 * @return string