In mail.php, we don't want to double encode fields so in send() create local variable...
[isso.git] / date.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright ©2002-[#]year[#] Blue Static
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 Blue Static
42 * @copyright Copyright ©2002 - [#]year[#], Blue Static
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 /**
86 * Constructor: sets the server's timezone
87 */
88 function __construct(&$registry)
89 {
90 $this->registry =& $registry;
91
92 $this->servertz = date('Z', TIMENOW) / 3600;
93 }
94
95 // ###################################################################
96 /**
97 * (PHP 4) Constructor
98 */
99 function Date(&$registry)
100 {
101 $this->__construct($registry);
102 }
103
104 // ###################################################################
105 /**
106 * Sets the user timezone variable
107 *
108 * @access public
109 *
110 * @param integer User time zone
111 */
112 function setUserTimezone($tz)
113 {
114 $this->usertz = $tz;
115 }
116
117 // ###################################################################
118 /**
119 * Gets the user timezone variable
120 *
121 * @access public
122 *
123 * @return integer The user timezone
124 */
125 function getUserTimezone()
126 {
127 return $this->usertz;
128 }
129
130 // ###################################################################
131 /**
132 * Computes the total offset, taking into account all the various
133 * options
134 *
135 * @access public
136 */
137 function fetch_offset()
138 {
139 $this->offsettz = $this->servertz - $this->usertz;
140 $this->offset = $this->offsettz * 3600;
141 }
142
143 // ###################################################################
144 /**
145 * Formats a UNIX timestamp to a certain date format in the proper time
146 * zone
147 *
148 * @access public
149 *
150 * @param string Format of the date (same as PHP's date() function)
151 * @param integer UNIX timestamp to format
152 * @param bool Adjust the date to the user's language?
153 *
154 * @return string Formatted date
155 */
156 function format($format, $timestamp = TIMENOW, $adjust = true)
157 {
158 if ($adjust)
159 {
160 $timestamp -= $this->offset;
161 }
162
163 return date($format, $timestamp);
164 }
165
166 // ###################################################################
167 /**
168 * Fetches an array of timezones for a <select> list
169 *
170 * @access public
171 *
172 * @return array List of timezones
173 */
174 function fetch_timezone_list()
175 {
176 $opt = array();
177
178 $opt['-12'] = _('(GMT - 12:00) Enitwetok, Kwajalien');
179 $opt['-11'] = _('(GMT - 11:00) Midway Island, Samoa');
180 $opt['-10'] = _('(GMT - 10:00) Hawaii');
181 $opt['-9'] = _('(GMT - 9:00) Alaska');
182 $opt['-8'] = _('(GMT - 8:00) Pacific Time (US &amp; Canada)');
183 $opt['-7'] = _('(GMT - 7:00) Mountain Time (US &amp; Canada)');
184 $opt['-6'] = _('(GMT - 6:00) Central Time (US &amp; Canada)');
185 $opt['-5'] = _('(GMT - 5:00) Eastern Time (US &amp; Canada)');
186 $opt['-4'] = _('(GMT - 4:00) Atlantic Time (Canada)');
187 $opt['-3.5'] = _('(GMT - 3:30) Newfoundland');
188 $opt['-3'] = _('(GMT - 3:00) Brazil, Buenos Aires, Georgetown');
189 $opt['-2'] = _('(GMT - 2:00) Mid-Atlantic, St. Helena');
190 $opt['-1'] = _('(GMT - 1:00) Azores, Cape Verde Islands');
191 $opt['0'] = _('(GMT) London, Dublin, Casablanca');
192 $opt['1'] = _('(GMT + 1:00) Berlin, Madrid, Paris');
193 $opt['2'] = _('(GMT + 2:00) Kaliningrad, South Africa, Warsaws');
194 $opt['3'] = _('(GMT + 3:00) Baghdad, Moscow, Nairobi');
195 $opt['3.5'] = _('(GMT + 3:30) Tehran');
196 $opt['4'] = _('(GMT + 4:00) Abu Dhabi, Tbilisi, Muscat');
197 $opt['4.5'] = _('(GMT + 4:30) Kabul');
198 $opt['5'] = _('(GMT + 5:00) Ekaterinburg, Islamabad, Tashkent');
199 $opt['5.5'] = _('(GMT + 5:30) Calcutta, Madras, New Delhi');
200 $opt['6'] = _('(GMT + 6:00) Almaty, Colomba, Dhakra');
201 $opt['7'] = _('(GMT + 7:00) Bangkok, Hanoi, Jakarta');
202 $opt['8'] = _('(GMT + 8:00) Beijing, Hong Kong, Singapore');
203 $opt['9'] = _('(GMT + 9:00) Seoul, Tokyo, Yakutsk');
204 $opt['9.5'] = _('(GMT + 9:30) Adelaide, Darwin');
205 $opt['10'] = _('(GMT + 10:00) Guam, Papua New Guinea, Sydney');
206 $opt['11'] = _('(GMT + 11:00) Magadan, New Caledonia, Solomon Islands');
207 $opt['12'] = _('(GMT + 12:00) Auckland, Wellington, Fiji');
208
209 return $opt;
210 }
211 }
212
213 /*=====================================================================*\
214 || ###################################################################
215 || # $HeadURL$
216 || # $Id$
217 || ###################################################################
218 \*=====================================================================*/
219 ?>