Delineating functions
[isso.git] / date.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]version[#]
5 || # Copyright ©2002-[#]year[#] Iris Studios, Inc.
6 || #
7 || # This program is free software; you can redistribute it and/or modify
8 || # it under the terms of the GNU General Public License as published by
9 || # the Free Software Foundation; version [#]gpl[#] of the License.
10 || #
11 || # This program is distributed in the hope that it will be useful, but
12 || # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 || # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 || # more details.
15 || #
16 || # You should have received a copy of the GNU General Public License along
17 || # with this program; if not, write to the Free Software Foundation, Inc.,
18 || # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
19 || ###################################################################
20 \*=====================================================================*/
21
22 /**
23 * Date formatting system
24 * date.php
25 *
26 * @package ISSO
27 */
28
29 /**
30 * Defined constant time
31 */
32 define('TIMENOW', time());
33
34 /**
35 * Date Formatting System
36 *
37 * This framework handles the complexities of date and time formatting
38 * by taking variables like global timezone and user timezone, then
39 * adjusting timestamps accordingly.
40 *
41 * @author Iris Studios, Inc.
42 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
43 * @version $Revision$
44 * @package ISSO
45 *
46 */
47 class Date
48 {
49 /**
50 * Framework registry object
51 * @var object
52 */
53 var $registry = null;
54
55 /**
56 * User timezone offset
57 * @var integer
58 */
59 var $usertz = 0;
60
61 /**
62 * Server's timezone offset; this is set using fetch_offset()
63 * @var integer
64 */
65 var $servertz = 0;
66
67 /**
68 * Total offset timezone; this is set using fetch_offset()
69 * @var integer
70 */
71 var $offsettz = 0;
72
73 /**
74 * Offset in seconds; this is set using fetch_offset()
75 * @var integer
76 */
77 var $offset = 0;
78
79 // ###################################################################
80 /**
81 * Constructor: sets the server's timezone
82 */
83 function __construct(&$registry)
84 {
85 $this->registry =& $registry;
86
87 $this->servertz = date('Z', TIMENOW) / 3600;
88 }
89
90 // ###################################################################
91 /**
92 * (PHP 4) Constructor
93 */
94 function Date(&$registry)
95 {
96 $this->__construct($registry);
97 }
98
99 // ###################################################################
100 /**
101 * Computes the total offset, taking into account all the various
102 * options
103 *
104 * @access public
105 */
106 function fetch_offset()
107 {
108 $this->offsettz = $this->servertz - $this->usertz;
109 $this->offset = $this->offsettz * 3600;
110 }
111
112 // ###################################################################
113 /**
114 * Formats a UNIX timestamp to a certain date format in the proper time
115 * zone
116 *
117 * @access public
118 *
119 * @param string Format of the date (same as PHP's date() function)
120 * @param integer UNIX timestamp to format
121 * @param bool Adjust the date to the user's language?
122 *
123 * @return string Formatted date
124 */
125 function format($format, $timestamp = TIMENOW, $adjust = true)
126 {
127 if ($adjust)
128 {
129 $timestamp -= $this->offset;
130 }
131
132 return date($format, $timestamp);
133 }
134
135 // ###################################################################
136 /**
137 * Fetches an array of timezones for a <select> list
138 *
139 * @access public
140 *
141 * @return array List of timezones
142 */
143 function fetch_timezone_list()
144 {
145 $opt = array();
146
147 $opt['-12'] = '(GMT - 12:00) Enitwetok, Kwajalien';
148 $opt['-11'] = '(GMT - 11:00) Midway Island, Samoa';
149 $opt['-10'] = '(GMT - 10:00) Hawaii';
150 $opt['-9'] = '(GMT - 9:00) Alaska';
151 $opt['-8'] = '(GMT - 8:00) Pacific Time (US &amp; Canada)';
152 $opt['-7'] = '(GMT - 7:00) Mountain Time (US &amp; Canada)';
153 $opt['-6'] = '(GMT - 6:00) Central Time (US &amp; Canada)';
154 $opt['-5'] = '(GMT - 5:00) Eastern Time (US &amp; Canada)';
155 $opt['-4'] = '(GMT - 4:00) Atlantic Time (Canada)';
156 $opt['-3.5'] = '(GMT - 3:30) Newfoundland';
157 $opt['-3'] = '(GMT - 3:00) Brazil, Buenos Aires, Georgetown';
158 $opt['-2'] = '(GMT - 2:00) Mid-Atlantic, St. Helena';
159 $opt['-1'] = '(GMT - 1:00) Azores, Cape Verde Islands';
160 $opt['0'] = '(GMT) London, Dublin, Casablanca';
161 $opt['1'] = '(GMT + 1:00) Berlin, Madrid, Paris';
162 $opt['2'] = '(GMT + 2:00) Kaliningrad, South Africa, Warsaws';
163 $opt['3'] = '(GMT + 3:00) Baghdad, Moscow, Nairobi';
164 $opt['3.5'] = '(GMT + 3:30) Tehran';
165 $opt['4'] = '(GMT + 4:00) Abu Dhabi, Tbilisi, Muscat';
166 $opt['4.5'] = '(GMT + 4:30) Kabul';
167 $opt['5'] = '(GMT + 5:00) Ekaterinburg, Islamabad, Tashkent';
168 $opt['5.5'] = '(GMT + 5:30) Calcutta, Madras, New Delhi';
169 $opt['6'] = '(GMT + 6:00) Almaty, Colomba, Dhakra';
170 $opt['7'] = '(GMT + 7:00) Bangkok, Hanoi, Jakarta';
171 $opt['8'] = '(GMT + 8:00) Beijing, Hong Kong, Singapore';
172 $opt['9'] = '(GMT + 9:00) Seoul, Tokyo, Yakutsk';
173 $opt['9.5'] = '(GMT + 9:30) Adelaide, Darwin';
174 $opt['10'] = '(GMT + 10:00) Guam, Papua New Guinea, Sydney';
175 $opt['11'] = '(GMT + 11:00) Magadan, New Caledonia, Solomon Islands';
176 $opt['12'] = '(GMT + 12:00) Auckland, Wellington, Fiji';
177
178 return $opt;
179 }
180 }
181
182 /*=====================================================================*\
183 || ###################################################################
184 || # $HeadURL$
185 || # $Id$
186 || ###################################################################
187 \*=====================================================================*/
188 ?>