tuan
10/28/2015 - 7:30 AM

Override datetime of Mage_Core_Model_Date #Magento, #Date

Override datetime of Mage_Core_Model_Date #Magento, #Date

<?php
/**
 * Features attributes helper
 *
 * @package    timezone
 * @author     tuanphpvn@gmail.com
 */
class BC_Future_Model_Date extends Mage_Core_Model_Date
{

    protected $timezone;

    public function __construct($timezone) {
        $this->timezone = $timezone;
        parent::__construct();
    }
    /**
     * Gets the store config timezone
     *
     * @return string
     */
    protected function _getConfigTimezone()
    {
        return $this->timezone;
    }

    public function timestamp($input = null)
    {
        if (is_null($input)) {
            $result = $this->gmtTimestamp();
        } else if (is_numeric($input)) {
            $result = $input;
        } else {
            $result = strtotime($input);
        }

        $date = new Zend_Date($result);
        $date->setTimeZone($this->timezone);
        $timestamp = $date->get(Zend_Date::TIMESTAMP) + $date->get(Zend_Date::TIMEZONE_SECS);

        unset($date);
        return $timestamp;
    }
}