Location: PHPKode > projects > Bugdar > upload/framework/date.php
<?php
/*=====================================================================*\
|| ###################################################################
|| # Blue Static ISSO Framework
|| # Copyright ©2002-[#]year[#] Blue Static
|| #
|| # This program is free software; you can redistribute it and/or modify
|| # it under the terms of the GNU General Public License as published by
|| # the Free Software Foundation; version [#]gpl[#] of the License.
|| #
|| # This program is distributed in the hope that it will be useful, but
|| # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|| # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|| # more details.
|| #
|| # You should have received a copy of the GNU General Public License along
|| # with this program; if not, write to the Free Software Foundation, Inc.,
|| # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|| ###################################################################
\*=====================================================================*/

/**
* Date formatting system
* date.php
*
* @package	ISSO
*/

/**
* Defined constant time
*/
define('TIMENOW', time());

/**
* Date Formatting System
*
* This framework handles the complexities of date and time formatting
* by taking variables like global timezone and user timezone, then
* adjusting timestamps accordingly.
*
* @author		Blue Static
* @copyright	Copyright ©2002 - [#]year[#], Blue Static
* @version		$Revision$
* @package		ISSO
* 
*/
class Date
{
	/**
	* Framework registry object
	* @var	object
	* @access	private
	*/
	var $registry = null;
	
	/**
	* User timezone offset
	* @var	integer
	* @access	public
	*/
	var $usertz = 0;
	
	/**
	* Server's timezone offset; this is set using fetch_offset()
	* @var	integer
	* @access	private
	*/
	var $servertz = 0;
	
	/**
	* Total offset timezone; this is set using fetch_offset()
	* @var	integer
	* @access	private
	*/
	var $offsettz = 0;
	
	/**
	* Offset in seconds; this is set using fetch_offset()
	* @var	integer
	* @access	private
	*/
	var $offset = 0;
	
	// ###################################################################
	/**
	* Constructor: sets the server's timezone
	*/
	function __construct(&$registry)
	{
		$this->registry =& $registry;
		
		$this->servertz = date('Z', TIMENOW) / 3600;
	}
	
	// ###################################################################
	/**
	* (PHP 4) Constructor
	*/
	function Date(&$registry)
	{
		$this->__construct($registry);
	}
	
	// ###################################################################
	/**
	* Sets the user timezone variable
	*
	* @access	public
	*
	* @param	integer	User time zone
	*/
	function setUserTimezone($tz)
	{
		$this->usertz = $tz;
	}
	
	// ###################################################################
	/**
	* Gets the user timezone variable
	*
	* @access	public
	*
	* @return	integer	The user timezone
	*/
	function getUserTimezone()
	{
		return $this->usertz;
	}
		
	// ###################################################################
	/**
	* Computes the total offset, taking into account all the various
	* options
	*
	* @access	public
	*/
	function fetch_offset()
	{
		$this->offsettz = $this->servertz - $this->usertz;
		$this->offset = $this->offsettz * 3600;
	}
	
	// ###################################################################
	/**
	* Formats a UNIX timestamp to a certain date format in the proper time
	* zone
	*
	* @access	public
	*
	* @param	string	Format of the date (same as PHP's date() function)
	* @param	integer	UNIX timestamp to format
	* @param	bool	Adjust the date to the user's language?
	*
	* @return	string	Formatted date
	*/
	function format($format, $timestamp = TIMENOW, $adjust = true)
	{
		if ($adjust)
		{
			$timestamp -= $this->offset;
		}
		
		return date($format, $timestamp);
	}
	
	// ###################################################################
	/**
	* Fetches an array of timezones for a <select> list
	*
	* @access	public
	*
	* @return	array	List of timezones
	*/
	function fetch_timezone_list()
	{
		$opt = array();
		
		$opt['-12']		= T('(GMT - 12:00) Enitwetok, Kwajalien');
		$opt['-11']		= T('(GMT - 11:00) Midway Island, Samoa');
		$opt['-10']		= T('(GMT - 10:00) Hawaii');
		$opt['-9']		= T('(GMT - 9:00) Alaska');
		$opt['-8']		= T('(GMT - 8:00) Pacific Time (US &amp; Canada)');
		$opt['-7']		= T('(GMT - 7:00) Mountain Time (US &amp; Canada)');
		$opt['-6']		= T('(GMT - 6:00) Central Time (US &amp; Canada)');
		$opt['-5']		= T('(GMT - 5:00) Eastern Time (US &amp; Canada)');
		$opt['-4']		= T('(GMT - 4:00) Atlantic Time (Canada)');
		$opt['-3.5']	= T('(GMT - 3:30) Newfoundland');
		$opt['-3']		= T('(GMT - 3:00)  Brazil, Buenos Aires, Georgetown');
		$opt['-2']		= T('(GMT - 2:00) Mid-Atlantic, St. Helena');
		$opt['-1']		= T('(GMT - 1:00) Azores, Cape Verde Islands');
		$opt['0']		= T('(GMT) London, Dublin, Casablanca');
		$opt['1']		= T('(GMT + 1:00) Berlin, Madrid, Paris');
		$opt['2']		= T('(GMT + 2:00) Kaliningrad, South Africa, Warsaws');
		$opt['3']		= T('(GMT + 3:00) Baghdad, Moscow, Nairobi');
		$opt['3.5']		= T('(GMT + 3:30) Tehran');
		$opt['4']		= T('(GMT + 4:00) Abu Dhabi, Tbilisi, Muscat');
		$opt['4.5']		= T('(GMT + 4:30) Kabul');
		$opt['5']		= T('(GMT + 5:00) Ekaterinburg, Islamabad, Tashkent');
		$opt['5.5']		= T('(GMT + 5:30) Calcutta, Madras, New Delhi');
		$opt['6']		= T('(GMT + 6:00) Almaty, Colomba, Dhakra');
		$opt['7']		= T('(GMT + 7:00) Bangkok, Hanoi, Jakarta');
		$opt['8']		= T('(GMT + 8:00) Beijing, Hong Kong, Singapore');
		$opt['9']		= T('(GMT + 9:00) Seoul, Tokyo, Yakutsk');
		$opt['9.5']		= T('(GMT + 9:30) Adelaide, Darwin');
		$opt['10']		= T('(GMT + 10:00) Guam, Papua New Guinea, Sydney');
		$opt['11']		= T('(GMT + 11:00) Magadan, New Caledonia, Solomon Islands');
		$opt['12']		= T('(GMT + 12:00) Auckland, Wellington, Fiji');
		
		return $opt;
	}
}

/*=====================================================================*\
|| ###################################################################
|| # $HeadURL$
|| # $Id$
|| ###################################################################
\*=====================================================================*/
?>
Return current item: Bugdar