Adding a $cleartos option to Mail::send()
[isso.git] / date.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Iris Studios Shared Object Framework [#]issoversion[#]
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 * @access private
53 */
54 var $registry = null;
55
56 /**
57 * User timezone offset
58 * @var integer
59 * @access public
60 */
61 var $usertz = 0;
62
63 /**
64 * Server's timezone offset; this is set using fetch_offset()
65 * @var integer
66 * @access private
67 */
68 var $servertz = 0;
69
70 /**
71 * Total offset timezone; this is set using fetch_offset()
72 * @var integer
73 * @access private
74 */
75 var $offsettz = 0;
76
77 /**
78 * Offset in seconds; this is set using fetch_offset()
79 * @var integer
80 * @access private
81 */
82 var $offset = 0;
83
84 /**
85 * Fields array that is used in this module
86 * @var array
87 * @access private
88 */
89 var $fields = array(
90 'usertz' => array(REQ_NO, null, false)
91 );
92
93 // ###################################################################
94 /**
95 * Constructor: sets the server's timezone
96 */
97 function __construct(&$registry)
98 {
99 $this->registry =& $registry;
100
101 $this->servertz = date('Z', TIMENOW) / 3600;
102 }
103
104 // ###################################################################
105 /**
106 * (PHP 4) Constructor
107 */
108 function Date(&$registry)
109 {
110 $this->__construct($registry);
111 }
112
113 // ###################################################################
114 /**
115 * Sets an ISSO field
116 *
117 * @access public
118 *
119 * @param string Field name
120 * @param mixed Value of the field
121 */
122 function set($name, $value)
123 {
124 $this->registry->do_set($name, $value, 'date');
125 }
126
127 // ###################################################################
128 /**
129 * Gets an ISSO field
130 *
131 * @access public
132 *
133 * @param string Field name
134 *
135 * @return mixed Value of the field
136 */
137 function get($fieldname)
138 {
139 return $this->registry->do_get($fieldname, 'date');
140 }
141
142 // ###################################################################
143 /**
144 * Computes the total offset, taking into account all the various
145 * options
146 *
147 * @access public
148 */
149 function fetch_offset()
150 {
151 $this->offsettz = $this->servertz - $this->usertz;
152 $this->offset = $this->offsettz * 3600;
153 }
154
155 // ###################################################################
156 /**
157 * Formats a UNIX timestamp to a certain date format in the proper time
158 * zone
159 *
160 * @access public
161 *
162 * @param string Format of the date (same as PHP's date() function)
163 * @param integer UNIX timestamp to format
164 * @param bool Adjust the date to the user's language?
165 *
166 * @return string Formatted date
167 */
168 function format($format, $timestamp = TIMENOW, $adjust = true)
169 {
170 if ($adjust)
171 {
172 $timestamp -= $this->offset;
173 }
174
175 return date($format, $timestamp);
176 }
177
178 // ###################################################################
179 /**
180 * Fetches an array of timezones for a <select> list
181 *
182 * @access public
183 *
184 * @return array List of timezones
185 */
186 function fetch_timezone_list()
187 {
188 $opt = array();
189
190 $opt['-12'] = $this->registry->modules['localize']->string('(GMT - 12:00) Enitwetok, Kwajalien');
191 $opt['-11'] = $this->registry->modules['localize']->string('(GMT - 11:00) Midway Island, Samoa');
192 $opt['-10'] = $this->registry->modules['localize']->string('(GMT - 10:00) Hawaii');
193 $opt['-9'] = $this->registry->modules['localize']->string('(GMT - 9:00) Alaska');
194 $opt['-8'] = $this->registry->modules['localize']->string('(GMT - 8:00) Pacific Time (US &amp; Canada)');
195 $opt['-7'] = $this->registry->modules['localize']->string('(GMT - 7:00) Mountain Time (US &amp; Canada)');
196 $opt['-6'] = $this->registry->modules['localize']->string('(GMT - 6:00) Central Time (US &amp; Canada)');
197 $opt['-5'] = $this->registry->modules['localize']->string('(GMT - 5:00) Eastern Time (US &amp; Canada)');
198 $opt['-4'] = $this->registry->modules['localize']->string('(GMT - 4:00) Atlantic Time (Canada)');
199 $opt['-3.5'] = $this->registry->modules['localize']->string('(GMT - 3:30) Newfoundland');
200 $opt['-3'] = $this->registry->modules['localize']->string('(GMT - 3:00) Brazil, Buenos Aires, Georgetown');
201 $opt['-2'] = $this->registry->modules['localize']->string('(GMT - 2:00) Mid-Atlantic, St. Helena');
202 $opt['-1'] = $this->registry->modules['localize']->string('(GMT - 1:00) Azores, Cape Verde Islands');
203 $opt['0'] = $this->registry->modules['localize']->string('(GMT) London, Dublin, Casablanca');
204 $opt['1'] = $this->registry->modules['localize']->string('(GMT + 1:00) Berlin, Madrid, Paris');
205 $opt['2'] = $this->registry->modules['localize']->string('(GMT + 2:00) Kaliningrad, South Africa, Warsaws');
206 $opt['3'] = $this->registry->modules['localize']->string('(GMT + 3:00) Baghdad, Moscow, Nairobi');
207 $opt['3.5'] = $this->registry->modules['localize']->string('(GMT + 3:30) Tehran');
208 $opt['4'] = $this->registry->modules['localize']->string('(GMT + 4:00) Abu Dhabi, Tbilisi, Muscat');
209 $opt['4.5'] = $this->registry->modules['localize']->string('(GMT + 4:30) Kabul');
210 $opt['5'] = $this->registry->modules['localize']->string('(GMT + 5:00) Ekaterinburg, Islamabad, Tashkent');
211 $opt['5.5'] = $this->registry->modules['localize']->string('(GMT + 5:30) Calcutta, Madras, New Delhi');
212 $opt['6'] = $this->registry->modules['localize']->string('(GMT + 6:00) Almaty, Colomba, Dhakra');
213 $opt['7'] = $this->registry->modules['localize']->string('(GMT + 7:00) Bangkok, Hanoi, Jakarta');
214 $opt['8'] = $this->registry->modules['localize']->string('(GMT + 8:00) Beijing, Hong Kong, Singapore');
215 $opt['9'] = $this->registry->modules['localize']->string('(GMT + 9:00) Seoul, Tokyo, Yakutsk');
216 $opt['9.5'] = $this->registry->modules['localize']->string('(GMT + 9:30) Adelaide, Darwin');
217 $opt['10'] = $this->registry->modules['localize']->string('(GMT + 10:00) Guam, Papua New Guinea, Sydney');
218 $opt['11'] = $this->registry->modules['localize']->string('(GMT + 11:00) Magadan, New Caledonia, Solomon Islands');
219 $opt['12'] = $this->registry->modules['localize']->string('(GMT + 12:00) Auckland, Wellington, Fiji');
220
221 return $opt;
222 }
223 }
224
225 /*=====================================================================*\
226 || ###################################################################
227 || # $HeadURL$
228 || # $Id$
229 || ###################################################################
230 \*=====================================================================*/
231 ?>