From c41e13fd1eac21c232f7300fe4a27ea73f18300c Mon Sep 17 00:00:00 2001 From: Ng Kiat Siong Date: Thu, 5 Aug 2021 02:57:37 +0800 Subject: [PATCH 1/3] Backported #1525 --- .../Block/Customer/Edit/Tab/View.php | 20 +++++-------- app/code/core/Mage/Core/Block/Abstract.php | 8 +++--- app/code/core/Mage/Core/Helper/Data.php | 28 ++++++++++--------- 3 files changed, 26 insertions(+), 30 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..bfe0c5d5b34 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,14 +79,9 @@ public function getCustomerLog() */ public function getCreateDate() { - if (!$this->getCustomer()->getCreatedAt()) { - return null; - } - return $this->_getCoreHelper()->formatDate( - $this->getCustomer()->getCreatedAt(), - Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, - true - ); + return ($date = $this->getCustomer()->getCreatedAt()) + ? $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false) + : null; } /** @@ -118,11 +113,9 @@ public function getStoreCreateDateTimezone() */ 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('customer')->__('Never'); + return ($date = $this->getCustomerLog()->getLoginAtTimestamp()) + ? $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false) + : Mage::helper('customer')->__('Never'); } /** @@ -255,6 +248,7 @@ public function isHidden() } /** + * @deprecated * Return instance of core helper * * @return Mage_Core_Helper_Data diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index 13845e418f2..500f5be6d3c 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]); @@ -1122,13 +1123,12 @@ public function helper($name) * @param string $date * @param string $format * @param bool $showTime + * @param bool $useTimezone * @return string */ - public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false) + public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false, $useTimezone = true) { - /** @var Mage_Core_Helper_Data $helper */ - $helper = $this->helper('core'); - return $helper->formatDate($date, $format, $showTime); + return $this->helper('core')->formatDate($date, $format, $showTime, $useTimezone); } /** diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index 2c78cd55116..d546293881d 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -153,30 +153,32 @@ 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 + * @param bool $useTimezone Convert to local datetime? * @return string */ - public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false) + public function formatDate($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) { - $format = Mage::app()->getLocale()->getDateTimeFormat($format); - } else { - $format = Mage::app()->getLocale()->getDateFormat($format); - } + $format = $showTime + ? Mage::app()->getLocale()->getDateTimeFormat($format) + : Mage::app()->getLocale()->getDateFormat($format); return $date->toString($format); } From 298999378424ebaa433ec034db6efcb096cf8949 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Mon, 26 Dec 2022 02:33:51 +0100 Subject: [PATCH 2/3] Reverted code format changes --- .../Block/Customer/Edit/Tab/View.php | 23 +++++++++++++------ app/code/core/Mage/Core/Block/Abstract.php | 4 +++- app/code/core/Mage/Core/Helper/Data.php | 8 ++++--- 3 files changed, 24 insertions(+), 11 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 bfe0c5d5b34..3367ae65e3c 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,9 +79,16 @@ public function getCustomerLog() */ public function getCreateDate() { - return ($date = $this->getCustomer()->getCreatedAt()) - ? $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false) - : null; + $date = $this->getCustomer()->getCreatedAt(); + if (!$date) { + return null; + } + return $this->formatDate( + $date, + Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, + true, + false + ); } /** @@ -113,9 +120,11 @@ 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('customer')->__('Never'); + $date = $this->getCustomerLog()->getLoginAtTimestamp(); + if ($date) { + return Mage::helper('core')->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false); + } + return Mage::helper('customer')->__('Never'); } /** @@ -248,10 +257,10 @@ public function isHidden() } /** - * @deprecated * Return instance of core helper * * @return Mage_Core_Helper_Data + * @deprecated */ protected function _getCoreHelper() { diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index 500f5be6d3c..b9b8a8207c2 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -1128,7 +1128,9 @@ public function helper($name) */ public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false, $useTimezone = true) { - return $this->helper('core')->formatDate($date, $format, $showTime, $useTimezone); + /** @var Mage_Core_Helper_Data $helper */ + $helper = $this->helper('core'); + return $helper->formatDate($date, $format, $showTime, $useTimezone); } /** diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index d546293881d..f24dd94b20f 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -176,9 +176,11 @@ public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMA } } - $format = $showTime - ? Mage::app()->getLocale()->getDateTimeFormat($format) - : Mage::app()->getLocale()->getDateFormat($format); + if ($showTime) { + $format = Mage::app()->getLocale()->getDateTimeFormat($format); + } else { + $format = Mage::app()->getLocale()->getDateFormat($format); + } return $date->toString($format); } From 35373f7f7165f1e4c3864cbb60fb1121d531eeb2 Mon Sep 17 00:00:00 2001 From: Sven Reichel Date: Mon, 26 Dec 2022 21:45:26 +0100 Subject: [PATCH 3/3] Added new method, reverted other changes --- .../Adminhtml/Block/Customer/Edit/Tab/View.php | 5 ++--- app/code/core/Mage/Core/Block/Abstract.php | 4 ++-- app/code/core/Mage/Core/Helper/Data.php | 17 +++++++++++++++-- 3 files changed, 19 insertions(+), 7 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 3367ae65e3c..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 @@ -83,7 +83,7 @@ public function getCreateDate() if (!$date) { return null; } - return $this->formatDate( + return $this->_getCoreHelper()->formatTimezoneDate( $date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, @@ -122,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, false); + return Mage::helper('core')->formatTimezoneDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true, false); } return Mage::helper('customer')->__('Never'); } @@ -260,7 +260,6 @@ public function isHidden() * Return instance of core helper * * @return Mage_Core_Helper_Data - * @deprecated */ protected function _getCoreHelper() { diff --git a/app/code/core/Mage/Core/Block/Abstract.php b/app/code/core/Mage/Core/Block/Abstract.php index b9b8a8207c2..988331dd434 100644 --- a/app/code/core/Mage/Core/Block/Abstract.php +++ b/app/code/core/Mage/Core/Block/Abstract.php @@ -1126,11 +1126,11 @@ public function helper($name) * @param bool $useTimezone * @return string */ - public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false, $useTimezone = true) + public function formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false) { /** @var Mage_Core_Helper_Data $helper */ $helper = $this->helper('core'); - return $helper->formatDate($date, $format, $showTime, $useTimezone); + return $helper->formatDate($date, $format, $showTime); } /** diff --git a/app/code/core/Mage/Core/Helper/Data.php b/app/code/core/Mage/Core/Helper/Data.php index f24dd94b20f..01063e8b094 100644 --- a/app/code/core/Mage/Core/Helper/Data.php +++ b/app/code/core/Mage/Core/Helper/Data.php @@ -153,13 +153,26 @@ 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|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, true); + } + + /** + * 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 formatDate($date = null, $format = Mage_Core_Model_Locale::FORMAT_TYPE_SHORT, $showTime = false, $useTimezone = true) + 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;