Skip to content

Commit

Permalink
Fixed incorrect datetime in block. (#1525)
Browse files Browse the repository at this point in the history
  • Loading branch information
kiatng authored Aug 4, 2021
1 parent 5cb3187 commit e69b326
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
17 changes: 7 additions & 10 deletions app/code/core/Mage/Adminhtml/Block/Customer/Edit/Tab/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,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;
}

public function getStoreCreateDate()
Expand Down Expand Up @@ -111,11 +109,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');
}

public function getStoreLastLoginDate()
Expand Down Expand Up @@ -218,6 +214,7 @@ public function isHidden()
}

/**
* @deprecated
* Return instance of core helper
*
* @return Mage_Core_Helper_Data
Expand Down
5 changes: 3 additions & 2 deletions app/code/core/Mage/Core/Block/Abstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -1128,11 +1128,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)
{
return $this->helper('core')->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 @@ -155,30 +155,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 e69b326

Please sign in to comment.