6

Over the weekend (2014-10-04 midnight through 2014-10-06 noon) I noticed that the customer created and last logged in dates were incorrect in the Admin.

Last Logged In: Oct 6, 8295 10:12:43 AM (Offline)

Last Logged In (America/New_York): Oct 4, 2014 11:58:15 AM (Offline)

Account Created on: Oct 6, 8187 10:12:43 AM

Account Created on (America/New_York): Oct 4, 2014 11:56:27 AM

This was happening only for updates (new customers, customer logins) that occurred within that timeframe; it stopped at noon on 2014-10-06. The database is correct.

After digging around, I found that the below methods in Mage_Adminhtml_Block_Customer_Edit_Tab_View are returning timestamps:

public function getCreateDate()
{
    return Mage::helper('core')->formatDate($this->getCustomer()->getCreatedAtTimestamp(),
        Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true);
}

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');
}

Looking at Mage_Core_Helper_Data::formatDate($date), there is a line that, after checking that the input date is not an instance of Zend_Date, it converts it using strtotime:

$date = Mage::app()->getLocale()->date(strtotime($date), null, null);

So it seems that it is converting an existing timestamp twice.

Can anyone tell me why this would only get screwed up for the aforementioned timeframe? I'm not sure why the block methods are converting to timestamps ahead of time, but it has never been an issue until now (and seems to no longer be an issue).

2 Answers 2

4

I resolved this issue by modifying the function getCreateDate() to take the Store Creation Date with this code:

public function getCreateDate()
{
  $date = Mage::app()->getLocale()->storeDate(
        $this->getCustomer()->getStoreId(),
        $this->getCustomer()->getCreatedAtTimestamp(),
        true
    );
    return $this->formatDate($date, Mage_Core_Model_Locale::FORMAT_TYPE_MEDIUM, true);
}

Hope it helps someone.

2
  • For future reference, this seems to be the correct answer even if it is not marked as accepted.
    – mbalparda
    Commented Apr 3, 2015 at 16:49
  • This did not solve it for us on M1937 in adminhtml customer/edit .... still the old time
    – snh_nl
    Commented Mar 9, 2018 at 10:31
0

Salvo's solution is to copy the code from public function getStoreCreateDate() to public function getCreateDate() & because it's the exact same code it ignores public function getStoreCreateDate() which comes after it...

So it makes it look cleaner but you could pretty much also just delete that one or the other (Depending on the fact you'd like the timezone to be displayed or not)

Therefore, same solution for public function getLastLoginDate(), I just copied the code from public function getStoreLastLoginDate() - I didn't delete anything, no need as the line with the timezone gets hidden automatically.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.