Beispiel #1
0
 public function convertDateToStoreTimestamp($date, $store = null)
 {
     try {
         if (Mage::getStoreConfigFlag('xtcore/compatibility_fixes/disable_timestamp_timezone_adjustment')) {
             $dateObj = new Zend_Date();
             $dateObj->set($date, Varien_Date::DATETIME_INTERNAL_FORMAT);
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP);
         }
         $dateObj = new Zend_Date();
         $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
         $dateObj->set($date, Varien_Date::DATETIME_INTERNAL_FORMAT);
         $dateObj->setLocale(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $store));
         $dateObj->setTimezone(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $store));
         $gmtOffset = $dateObj->getGmtOffset();
         if ($gmtOffset >= 0) {
             if (Mage::getStoreConfigFlag('xtcore/compatibility_fixes/zend_date_gmt_offset')) {
                 // Note: Some Zend_Date versions always return a positive $gmtOffset. Thus, we replace + with - below if affected by this.
                 return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) - $gmtOffset;
             } else {
                 return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) + $gmtOffset;
             }
         } else {
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) - $gmtOffset;
         }
     } catch (Exception $e) {
         return null;
     }
 }
Beispiel #2
0
 public function convertDateToStoreTimestamp($date, $store = null)
 {
     try {
         $dateObj = new Zend_Date();
         $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
         $dateObj->set($date, Varien_Date::DATETIME_INTERNAL_FORMAT);
         $dateObj->setLocale(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $store));
         $dateObj->setTimezone(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $store));
         $gmtOffset = $dateObj->getGmtOffset();
         if ($gmtOffset >= 0) {
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) + $gmtOffset;
         } else {
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) - $gmtOffset;
         }
     } catch (Exception $e) {
         return null;
     }
 }
Beispiel #3
0
 public function convertDateToStoreTimestamp($date, $store = null)
 {
     try {
         $dateObj = new Zend_Date();
         $dateObj->setTimezone(Mage_Core_Model_Locale::DEFAULT_TIMEZONE);
         $dateObj->set($date, Varien_Date::DATETIME_INTERNAL_FORMAT);
         $dateObj->setLocale(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_LOCALE, $store));
         $dateObj->setTimezone(Mage::getStoreConfig(Mage_Core_Model_Locale::XML_PATH_DEFAULT_TIMEZONE, $store));
         $gmtOffset = $dateObj->getGmtOffset();
         if ($gmtOffset >= 0) {
             // Note: Some Zend_Date versions always return a positive $gmtOffset. Thus, replace + with - below if you're affected by this.
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) + $gmtOffset;
         } else {
             return (int) $dateObj->get(null, Zend_Date::TIMESTAMP) - $gmtOffset;
         }
     } catch (Exception $e) {
         return null;
     }
 }
Beispiel #4
0
 /**
  * Test for False Month Addition
  */
 public function testGmtOffsetValues()
 {
     date_default_timezone_set('Pacific/Auckland');
     $time = time();
     $date = new Zend_Date($time);
     $stamp = $date->getGmtOffset();
     $localtime = localtime($time, true);
     $offset = mktime($localtime['tm_hour'], $localtime['tm_min'], $localtime['tm_sec'], $localtime['tm_mon'] + 1, $localtime['tm_mday'], $localtime['tm_year'] + 1900) - gmmktime($localtime['tm_hour'], $localtime['tm_min'], $localtime['tm_sec'], $localtime['tm_mon'] + 1, $localtime['tm_mday'], $localtime['tm_year'] + 1900);
     $this->assertEquals($stamp, $offset);
     $date->addMonth(6);
     $stamp = $date->getGmtOffset();
     $localtime = localtime($time, true);
     $offset = mktime($localtime['tm_hour'], $localtime['tm_min'], $localtime['tm_sec'], $localtime['tm_mon'] + 7, $localtime['tm_mday'], $localtime['tm_year'] + 1900) - gmmktime($localtime['tm_hour'], $localtime['tm_min'], $localtime['tm_sec'], $localtime['tm_mon'] + 7, $localtime['tm_mday'], $localtime['tm_year'] + 1900);
     $this->assertEquals($stamp, $offset);
 }
Beispiel #5
0
 /**
  * Retrives global timezone offset in seconds
  *
  * @param boolean $isMysql If true retrives mysql formmatted offset (+00:00) in hours
  * @return int
  */
 public function getTimeZoneOffset($isMysql = false)
 {
     $date = new Zend_Date();
     $date->setTimezone($this->getTimezone());
     if ($isMysql) {
         $offsetInt = -$date->getGmtOffset();
         $offset = ($offsetInt >= 0 ? '+' : '-') . sprintf('%02.0f', round(abs($offsetInt / 3600))) . ':' . sprintf('%02.0f', abs(round((abs($offsetInt) - round(abs($offsetInt / 3600)) * 3600) / 60)));
         return $offset;
     } else {
         return $date->getGmtOffset();
     }
 }
Beispiel #6
0
 /**
  * The number of days in $date subtracted from $this.
  *
  * Zero when both date/times occur on the same day.
  * POSITIVE when $date is YOUNGER than $this
  * Negative when $date is older than $this
  *
  * This function ignores the Timezone and is only concerned with
  * the actual display date of the date: 2 timestamps in different
  * timezones can be the same GMT second, but can still occur on
  * different days.
  *
  * @param \Zend_Date $date
  * @param \Zend_Locale $locale optional (not used)
  * @return type
  */
 public function diffDays(\Zend_Date $date = null, $locale = null)
 {
     $val1 = (int) (($this->getUnixTimestamp() - $this->getGmtOffset()) / self::DAY_SECONDS);
     if (null === $date) {
         // We must use date objects as unix timestamps do not take
         // account of leap seconds.
         $val2 = (int) (time() / self::DAY_SECONDS);
     } else {
         $val2 = (int) (($date->getUnixTimestamp() - $date->getGmtOffset()) / self::DAY_SECONDS);
     }
     return $val1 - $val2;
 }