Skip to content

Commit

Permalink
Backported OpenMage#1525
Browse files Browse the repository at this point in the history
  • Loading branch information
kiatng authored and fballiano committed Dec 25, 2022
1 parent 5e98099 commit c41e13f
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 30 deletions.
20 changes: 7 additions & 13 deletions app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -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');
}

/**
Expand Down Expand Up @@ -255,6 +248,7 @@ public function isHidden()
}

/**
* @deprecated
* Return instance of core helper
*
* @return Mage_Core_Helper_Data
Expand Down
8 changes: 4 additions & 4 deletions app/code/core/Mage/Core/Block/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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);
}

/**
Expand Down
28 changes: 15 additions & 13 deletions app/code/core/Mage/Core/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit c41e13f

Please sign in to comment.