Overview

Packages

  • currencysymbol
  • MAbout
  • Mage
    • Admin
    • Adminhtml
    • AdminNotification
    • Api
    • Api2
    • Authorizenet
    • Backup
    • Bundle
    • Captcha
    • Catalog
    • CatalogIndex
    • CatalogInventory
    • CatalogRule
    • CatalogSearch
    • Centinel
    • Checkout
    • Cms
    • Compiler
    • Connect
    • Contacts
    • Core
    • Cron
    • CurrencySymbol
    • Customer
    • Dataflow
    • Directory
    • DirtectPost
    • Downloadable
    • Eav
    • GiftMessage
    • GoogleAnalytics
    • GoogleBase
    • GoogleCheckout
    • ImportExport
    • Index
    • Install
    • Log
    • Media
    • Newsletter
    • Oauth
    • Page
    • PageCache
    • Paygate
    • Payment
    • Paypal
    • PaypalUk
    • Persistent
    • Poll
    • ProductAlert
    • Rating
    • Reports
    • Review
    • Rss
    • Rule
    • Sales
    • SalesRule
    • Sedfriend
    • Sendfriend
    • Shipping
    • Sitemap
    • Tag
    • Tax
    • Usa
    • Weee
    • Widget
    • Wishlist
    • XmlConnect
  • None
  • Phoenix
    • Moneybookers
  • PHP
  • Zend
    • Date
    • Mime
    • XmlRpc

Classes

  • Mage
  • Mage_Adminhtml_Block_Html_Date
  • Mage_Adminhtml_Block_Html_Select
  • Mage_Api_Model_Wsdl_Config_Element
  • Mage_Captcha_Adminhtml_RefreshController
  • Mage_Captcha_RefreshController
  • Mage_Core_AjaxController
  • Mage_Core_Block_Abstract
  • Mage_Core_Block_Flush
  • Mage_Core_Block_Html_Calendar
  • Mage_Core_Block_Html_Date
  • Mage_Core_Block_Html_Link
  • Mage_Core_Block_Html_Select
  • Mage_Core_Block_Messages
  • Mage_Core_Block_Profiler
  • Mage_Core_Block_Store_Switcher
  • Mage_Core_Block_Template
  • Mage_Core_Block_Template_Facade
  • Mage_Core_Block_Template_Smarty
  • Mage_Core_Block_Template_Zend
  • Mage_Core_Block_Text
  • Mage_Core_Block_Text_List
  • Mage_Core_Block_Text_List_Item
  • Mage_Core_Block_Text_List_Link
  • Mage_Core_Block_Text_Tag
  • Mage_Core_Block_Text_Tag_Css
  • Mage_Core_Block_Text_Tag_Css_Admin
  • Mage_Core_Block_Text_Tag_Debug
  • Mage_Core_Block_Text_Tag_Js
  • Mage_Core_Block_Text_Tag_Meta
  • Mage_Core_Controller_Front_Action
  • Mage_Core_Controller_Front_Router
  • Mage_Core_Controller_Request_Http
  • Mage_Core_Controller_Response_Http
  • Mage_Core_Controller_Varien_Action
  • Mage_Core_Controller_Varien_Front
  • Mage_Core_Controller_Varien_Router_Abstract
  • Mage_Core_Controller_Varien_Router_Admin
  • Mage_Core_Controller_Varien_Router_Default
  • Mage_Core_Controller_Varien_Router_Standard
  • Mage_Core_Helper_Abstract
  • Mage_Core_Helper_Cookie
  • Mage_Core_Helper_Data
  • Mage_Core_Helper_File_Storage
  • Mage_Core_Helper_File_Storage_Database
  • Mage_Core_Helper_Hint
  • Mage_Core_Helper_Http
  • Mage_Core_Helper_Js
  • Mage_Core_Helper_String
  • Mage_Core_Helper_Translate
  • Mage_Core_Helper_Url
  • Mage_Core_Helper_Url_Rewrite
  • Mage_Core_IndexController
  • Mage_Core_Model_Abstract
  • Mage_Core_Model_App
  • Mage_Core_Model_App_Area
  • Mage_Core_Model_App_Emulation
  • Mage_Core_Model_Cache
  • Mage_Core_Model_Calculator
  • Mage_Core_Model_Config
  • Mage_Core_Model_Config_Base
  • Mage_Core_Model_Config_Data
  • Mage_Core_Model_Config_Element
  • Mage_Core_Model_Config_Options
  • Mage_Core_Model_Config_System
  • Mage_Core_Model_Cookie
  • Mage_Core_Model_Date
  • Mage_Core_Model_Design
  • Mage_Core_Model_Design_Package
  • Mage_Core_Model_Design_Source_Design
  • Mage_Core_Model_Email
  • Mage_Core_Model_Email_Info
  • Mage_Core_Model_Email_Template
  • Mage_Core_Model_Email_Template_Filter
  • Mage_Core_Model_Email_Template_Mailer
  • Mage_Core_Model_Email_Transport
  • Mage_Core_Model_Encryption
  • Mage_Core_Model_File_Storage
  • Mage_Core_Model_File_Storage_Abstract
  • Mage_Core_Model_File_Storage_Database
  • Mage_Core_Model_File_Storage_Database_Abstract
  • Mage_Core_Model_File_Storage_Directory_Database
  • Mage_Core_Model_File_Storage_File
  • Mage_Core_Model_File_Storage_Flag
  • Mage_Core_Model_File_Uploader
  • Mage_Core_Model_File_Validator_AvailablePath
  • Mage_Core_Model_File_Validator_NotProtectedExtension
  • Mage_Core_Model_Flag
  • Mage_Core_Model_Input_Filter
  • Mage_Core_Model_Input_Filter_MaliciousCode
  • Mage_Core_Model_Language
  • Mage_Core_Model_Layout
  • Mage_Core_Model_Layout_Data
  • Mage_Core_Model_Layout_Element
  • Mage_Core_Model_Layout_Update
  • Mage_Core_Model_Locale
  • Mage_Core_Model_Locale_Config
  • Mage_Core_Model_Log_Adapter
  • Mage_Core_Model_Magento_Api
  • Mage_Core_Model_Magento_Api_V2
  • Mage_Core_Model_Message
  • Mage_Core_Model_Message_Abstract
  • Mage_Core_Model_Message_Collection
  • Mage_Core_Model_Message_Error
  • Mage_Core_Model_Message_Notice
  • Mage_Core_Model_Message_Success
  • Mage_Core_Model_Message_Warning
  • Mage_Core_Model_Mysql4_Abstract
  • Mage_Core_Model_Mysql4_Cache
  • Mage_Core_Model_Mysql4_Collection_Abstract
  • Mage_Core_Model_Mysql4_Config
  • Mage_Core_Model_Mysql4_Config_Data
  • Mage_Core_Model_Mysql4_Config_Data_Collection
  • Mage_Core_Model_Mysql4_Design
  • Mage_Core_Model_Mysql4_Design_Collection
  • Mage_Core_Model_Mysql4_Design_Package_Collection
  • Mage_Core_Model_Mysql4_Design_Theme
  • Mage_Core_Model_Mysql4_Email_Template
  • Mage_Core_Model_Mysql4_Email_Template_Collection
  • Mage_Core_Model_Mysql4_File_Storage_Abstract
  • Mage_Core_Model_Mysql4_File_Storage_Database
  • Mage_Core_Model_Mysql4_File_Storage_Directory_Database
  • Mage_Core_Model_Mysql4_File_Storage_File
  • Mage_Core_Model_Mysql4_Flag
  • Mage_Core_Model_Mysql4_Language
  • Mage_Core_Model_Mysql4_Language_Collection
  • Mage_Core_Model_Mysql4_Layout
  • Mage_Core_Model_Mysql4_Resource
  • Mage_Core_Model_Mysql4_Session
  • Mage_Core_Model_Mysql4_Store
  • Mage_Core_Model_Mysql4_Store_Collection
  • Mage_Core_Model_Mysql4_Store_Group
  • Mage_Core_Model_Mysql4_Store_Group_Collection
  • Mage_Core_Model_Mysql4_Translate
  • Mage_Core_Model_Mysql4_Translate_String
  • Mage_Core_Model_Mysql4_Url_Rewrite
  • Mage_Core_Model_Mysql4_Url_Rewrite_Collection
  • Mage_Core_Model_Mysql4_Variable
  • Mage_Core_Model_Mysql4_Variable_Collection
  • Mage_Core_Model_Mysql4_Website
  • Mage_Core_Model_Mysql4_Website_Collection
  • Mage_Core_Model_Observer
  • Mage_Core_Model_Resource
  • Mage_Core_Model_Resource_Abstract
  • Mage_Core_Model_Resource_Cache
  • Mage_Core_Model_Resource_Config
  • Mage_Core_Model_Resource_Config_Data
  • Mage_Core_Model_Resource_Config_Data_Collection
  • Mage_Core_Model_Resource_Db_Abstract
  • Mage_Core_Model_Resource_Db_Collection_Abstract
  • Mage_Core_Model_Resource_Design
  • Mage_Core_Model_Resource_Design_Collection
  • Mage_Core_Model_Resource_Design_Package_Collection
  • Mage_Core_Model_Resource_Email_Template
  • Mage_Core_Model_Resource_Email_Template_Collection
  • Mage_Core_Model_Resource_Entity_Abstract
  • Mage_Core_Model_Resource_Entity_Table
  • Mage_Core_Model_Resource_File_Storage_Abstract
  • Mage_Core_Model_Resource_File_Storage_Database
  • Mage_Core_Model_Resource_File_Storage_Directory_Database
  • Mage_Core_Model_Resource_File_Storage_File
  • Mage_Core_Model_Resource_Flag
  • Mage_Core_Model_Resource_Helper_Abstract
  • Mage_Core_Model_Resource_Helper_Mysql4
  • Mage_Core_Model_Resource_Iterator
  • Mage_Core_Model_Resource_Language
  • Mage_Core_Model_Resource_Language_Collection
  • Mage_Core_Model_Resource_Layout
  • Mage_Core_Model_Resource_Resource
  • Mage_Core_Model_Resource_Session
  • Mage_Core_Model_Resource_Setup
  • Mage_Core_Model_Resource_Setup_Query_Modifier
  • Mage_Core_Model_Resource_Store
  • Mage_Core_Model_Resource_Store_Collection
  • Mage_Core_Model_Resource_Store_Group
  • Mage_Core_Model_Resource_Store_Group_Collection
  • Mage_Core_Model_Resource_Transaction
  • Mage_Core_Model_Resource_Translate
  • Mage_Core_Model_Resource_Translate_String
  • Mage_Core_Model_Resource_Type_Abstract
  • Mage_Core_Model_Resource_Type_Db
  • Mage_Core_Model_Resource_Type_Db_Mysqli
  • Mage_Core_Model_Resource_Type_Db_Mysqli_Setup
  • Mage_Core_Model_Resource_Type_Db_Pdo_Mysql
  • Mage_Core_Model_Resource_Url_Rewrite
  • Mage_Core_Model_Resource_Url_Rewrite_Collection
  • Mage_Core_Model_Resource_Variable
  • Mage_Core_Model_Resource_Variable_Collection
  • Mage_Core_Model_Resource_Website
  • Mage_Core_Model_Resource_Website_Collection
  • Mage_Core_Model_Session
  • Mage_Core_Model_Session_Abstract
  • Mage_Core_Model_Session_Abstract_Varien
  • Mage_Core_Model_Session_Abstract_Zend
  • Mage_Core_Model_Source_Email_Variables
  • Mage_Core_Model_Store
  • Mage_Core_Model_Store_Api
  • Mage_Core_Model_Store_Api_V2
  • Mage_Core_Model_Store_Group
  • Mage_Core_Model_Template
  • Mage_Core_Model_Translate
  • Mage_Core_Model_Translate_Expr
  • Mage_Core_Model_Translate_Inline
  • Mage_Core_Model_Translate_String
  • Mage_Core_Model_Url
  • Mage_Core_Model_Url_Rewrite
  • Mage_Core_Model_Url_Validator
  • Mage_Core_Model_Variable
  • Mage_Core_Model_Variable_Config
  • Mage_Core_Model_Variable_Observer
  • Mage_Core_Model_Website
  • Mage_Page_Block_Switch
  • Mage_Page_Block_Template_Container
  • Mage_Page_Block_Template_Links
  • Mage_Page_Block_Template_Links_Block
  • Mage_Sales_Model_Quote_Address_Total_Collector

Exceptions

  • Mage_Core_Controller_Varien_Exception
  • Mage_Core_Exception
  • Mage_Core_Model_Session_Exception
  • Mage_Core_Model_Store_Exception

Functions

  • destruct
  • is_dir_writeable
  • is_empty_date
  • mageCoreErrorHandler
  • mageDebugBacktrace
  • mageDelTree
  • mageFindClassFile
  • mageParseCsv
  • mageSendErrorFooter
  • mageSendErrorHeader
  • mageUndoMagicQuotes
  • now
  • sys_get_temp_dir
  • uc_words
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Magento
  4:  *
  5:  * NOTICE OF LICENSE
  6:  *
  7:  * This source file is subject to the Open Software License (OSL 3.0)
  8:  * that is bundled with this package in the file LICENSE.txt.
  9:  * It is also available through the world-wide-web at this URL:
 10:  * http://opensource.org/licenses/osl-3.0.php
 11:  * If you did not receive a copy of the license and are unable to
 12:  * obtain it through the world-wide-web, please send an email
 13:  * to license@magentocommerce.com so we can send you a copy immediately.
 14:  *
 15:  * DISCLAIMER
 16:  *
 17:  * Do not edit or add to this file if you wish to upgrade Magento to newer
 18:  * versions in the future. If you wish to customize Magento for your
 19:  * needs please refer to http://www.magentocommerce.com for more information.
 20:  *
 21:  * @category    Mage
 22:  * @package     Mage_Core
 23:  * @copyright   Copyright (c) 2012 Magento Inc. (http://www.magentocommerce.com)
 24:  * @license     http://opensource.org/licenses/osl-3.0.php  Open Software License (OSL 3.0)
 25:  */
 26: 
 27: 
 28: /**
 29:  * Date conversion model
 30:  *
 31:  * @author      Magento Core Team <core@magentocommerce.com>
 32:  */
 33: class Mage_Core_Model_Date
 34: {
 35:     /**
 36:      * Current config offset in seconds
 37:      *
 38:      * @var int
 39:      */
 40:     private $_offset = 0;
 41: 
 42:     /**
 43:      * Current system offset in seconds
 44:      *
 45:      * @var int
 46:      */
 47:     private $_systemOffset = 0;
 48: 
 49:     /**
 50:      * Init offset
 51:      *
 52:      */
 53:     public function __construct()
 54:     {
 55:         $this->_offset = $this->calculateOffset($this->_getConfigTimezone());
 56:         $this->_systemOffset = $this->calculateOffset();
 57:     }
 58: 
 59:     /**
 60:      * Gets the store config timezone
 61:      *
 62:      * @return string
 63:      */
 64:     protected function _getConfigTimezone()
 65:     {
 66:         return Mage::app()->getStore()->getConfig('general/locale/timezone');
 67:     }
 68: 
 69:     /**
 70:      * Calculates timezone offset
 71:      *
 72:      * @param  string $timezone
 73:      * @return int offset between timezone and gmt
 74:      */
 75:     public function calculateOffset($timezone = null)
 76:     {
 77:         $result = true;
 78:         $offset = 0;
 79: 
 80:         if (!is_null($timezone)){
 81:             $oldzone = @date_default_timezone_get();
 82:             $result = date_default_timezone_set($timezone);
 83:         }
 84: 
 85:         if ($result === true) {
 86:             $offset = gmmktime(0, 0, 0, 1, 2, 1970) - mktime(0, 0, 0, 1, 2, 1970);
 87:         }
 88: 
 89:         if (!is_null($timezone)){
 90:             date_default_timezone_set($oldzone);
 91:         }
 92: 
 93:         return $offset;
 94:     }
 95: 
 96:     /**
 97:      * Forms GMT date
 98:      *
 99:      * @param  string $format
100:      * @param  int|string $input date in current timezone
101:      * @return string
102:      */
103:     public function gmtDate($format = null, $input = null)
104:     {
105:         if (is_null($format)) {
106:             $format = 'Y-m-d H:i:s';
107:         }
108: 
109:         $date = $this->gmtTimestamp($input);
110: 
111:         if ($date === false) {
112:             return false;
113:         }
114: 
115:         $result = date($format, $date);
116:         return $result;
117:     }
118: 
119:     /**
120:      * Converts input date into date with timezone offset
121:      * Input date must be in GMT timezone
122:      *
123:      * @param  string $format
124:      * @param  int|string $input date in GMT timezone
125:      * @return string
126:      */
127:     public function date($format = null, $input = null)
128:     {
129:         if (is_null($format)) {
130:             $format = 'Y-m-d H:i:s';
131:         }
132: 
133:         $result = date($format, $this->timestamp($input));
134:         return $result;
135:     }
136: 
137:     /**
138:      * Forms GMT timestamp
139:      *
140:      * @param  int|string $input date in current timezone
141:      * @return int
142:      */
143:     public function gmtTimestamp($input = null)
144:     {
145:         if (is_null($input)) {
146:             return gmdate('U');
147:         } else if (is_numeric($input)) {
148:             $result = $input;
149:         } else {
150:             $result = strtotime($input);
151:         }
152: 
153:         if ($result === false) {
154:             // strtotime() unable to parse string (it's not a date or has incorrect format)
155:             return false;
156:         }
157: 
158:         $date      = Mage::app()->getLocale()->date($result);
159:         $timestamp = $date->get(Zend_Date::TIMESTAMP) - $date->get(Zend_Date::TIMEZONE_SECS);
160: 
161:         unset($date);
162:         return $timestamp;
163: 
164:     }
165: 
166:     /**
167:      * Converts input date into timestamp with timezone offset
168:      * Input date must be in GMT timezone
169:      *
170:      * @param  int|string $input date in GMT timezone
171:      * @return int
172:      */
173:     public function timestamp($input = null)
174:     {
175:         if (is_null($input)) {
176:             $result = $this->gmtTimestamp();
177:         } else if (is_numeric($input)) {
178:             $result = $input;
179:         } else {
180:             $result = strtotime($input);
181:         }
182: 
183:         $date      = Mage::app()->getLocale()->date($result);
184:         $timestamp = $date->get(Zend_Date::TIMESTAMP) + $date->get(Zend_Date::TIMEZONE_SECS);
185: 
186:         unset($date);
187:         return $timestamp;
188:     }
189: 
190:     /**
191:      * Get current timezone offset in seconds/minutes/hours
192:      *
193:      * @param  string $type
194:      * @return int
195:      */
196:     public function getGmtOffset($type = 'seconds')
197:     {
198:         $result = $this->_offset;
199:         switch ($type) {
200:             case 'seconds':
201:             default:
202:                 break;
203: 
204:             case 'minutes':
205:                 $result = $result / 60;
206:                 break;
207: 
208:             case 'hours':
209:                 $result = $result / 60 / 60;
210:                 break;
211:         }
212:         return $result;
213:     }
214: 
215:     /**
216:      * Deprecated since 1.1.7
217:      */
218:     public function checkDateTime($year, $month, $day, $hour = 0, $minute = 0, $second = 0)
219:     {
220:         if (!checkdate($month, $day, $year)) {
221:             return false;
222:         }
223:         foreach (array('hour' => 23, 'minute' => 59, 'second' => 59) as $var => $maxValue) {
224:             $value = (int)$$var;
225:             if (($value < 0) || ($value > $maxValue)) {
226:                 return false;
227:             }
228:         }
229:         return true;
230:     }
231: 
232:     /**
233:      * Deprecated since 1.1.7
234:      */
235:     public function parseDateTime($dateTimeString, $dateTimeFormat)
236:     {
237:         // look for supported format
238:         $isSupportedFormatFound = false;
239: 
240:         $formats = array(
241:             // priority is important!
242:             '%m/%d/%y %I:%M' => array(
243:                 '/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2})/',
244:                 array('y' => 3, 'm' => 1, 'd' => 2, 'h' => 4, 'i' => 5)
245:             ),
246:             'm/d/y h:i' => array(
247:                 '/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,2}) ([0-9]{1,2}):([0-9]{1,2})/',
248:                 array('y' => 3, 'm' => 1, 'd' => 2, 'h' => 4, 'i' => 5)
249:             ),
250:             '%m/%d/%y' => array('/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,2})/', array('y' => 3, 'm' => 1, 'd' => 2)),
251:             'm/d/y' => array('/^([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,2})/', array('y' => 3, 'm' => 1, 'd' => 2)),
252:         );
253: 
254:         foreach ($formats as $supportedFormat => $regRule) {
255:             if (false !== strpos($dateTimeFormat, $supportedFormat, 0)) {
256:                 $isSupportedFormatFound = true;
257:                 break;
258:             }
259:         }
260:         if (!$isSupportedFormatFound) {
261:             Mage::throwException(Mage::helper('core')->__('Date/time format "%s" is not supported.', $dateTimeFormat));
262:         }
263: 
264:         // apply reg rule to found format
265:         $regex = array_shift($regRule);
266:         $mask  = array_shift($regRule);
267:         if (!preg_match($regex, $dateTimeString, $matches)) {
268:             Mage::throwException(Mage::helper('core')->__('Specified date/time "%1$s" do not match format "%2$s".', $dateTimeString, $dateTimeFormat));
269:         }
270: 
271:         // make result
272:         $result = array();
273:         foreach (array('y', 'm', 'd', 'h', 'i', 's') as $key) {
274:             $value = 0;
275:             if (isset($mask[$key]) && isset($matches[$mask[$key]])) {
276:                 $value = (int)$matches[$mask[$key]];
277:             }
278:             $result[] = $value;
279:         }
280: 
281:         // make sure to return full year
282:         if ($result[0] < 100) {
283:             $result[0] = 2000 + $result[0];
284:         }
285: 
286:         return $result;
287:     }
288: }
289: 
Magento 1.7.0.2 API documentation generated by ApiGen 2.8.0