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