]>
src.bluestatic.org Git - bugdar.git/blob - framework/date.php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2002-[#]year[#] Blue Static
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.
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
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 \*=====================================================================*/
23 * Date formatting system
30 * Defined constant time
32 define('TIMENOW', time());
35 * Date Formatting System
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.
42 * @copyright Copyright (c)2002 - [#]year[#], Blue Static
50 * Framework registry object
57 * User timezone offset
64 * Server's timezone offset; this is set using fetch_offset()
71 * Total offset timezone; this is set using fetch_offset()
78 * Offset in seconds; this is set using fetch_offset()
84 // ###################################################################
86 * Constructor: sets the server's timezone
88 function __construct(&$registry)
90 $this->registry
=& $registry;
92 $this->servertz
= date('Z', TIMENOW
) / 3600;
95 // ###################################################################
99 function Date(&$registry)
101 $this->__construct($registry);
104 // ###################################################################
106 * Sets the user timezone variable
110 * @param integer User time zone
112 function setUserTimezone($tz)
117 // ###################################################################
119 * Gets the user timezone variable
123 * @return integer The user timezone
125 function getUserTimezone()
127 return $this->usertz
;
130 // ###################################################################
132 * Computes the total offset, taking into account all the various
137 function fetch_offset()
139 $this->offsettz
= $this->servertz
- $this->usertz
;
140 $this->offset
= $this->offsettz
* 3600;
143 // ###################################################################
145 * Formats a UNIX timestamp to a certain date format in the proper time
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?
154 * @return string Formatted date
156 function format($format, $timestamp = TIMENOW
, $adjust = true)
160 $timestamp -= $this->offset
;
163 return date($format, $timestamp);
166 // ###################################################################
168 * Fetches an array of timezones for a <select> list
172 * @return array List of timezones
174 function fetch_timezone_list()
178 $opt['-12'] = T('(GMT - 12:00) Enitwetok, Kwajalien');
179 $opt['-11'] = T('(GMT - 11:00) Midway Island, Samoa');
180 $opt['-10'] = T('(GMT - 10:00) Hawaii');
181 $opt['-9'] = T('(GMT - 9:00) Alaska');
182 $opt['-8'] = T('(GMT - 8:00) Pacific Time (US & Canada)');
183 $opt['-7'] = T('(GMT - 7:00) Mountain Time (US & Canada)');
184 $opt['-6'] = T('(GMT - 6:00) Central Time (US & Canada)');
185 $opt['-5'] = T('(GMT - 5:00) Eastern Time (US & Canada)');
186 $opt['-4'] = T('(GMT - 4:00) Atlantic Time (Canada)');
187 $opt['-3.5'] = T('(GMT - 3:30) Newfoundland');
188 $opt['-3'] = T('(GMT - 3:00) Brazil, Buenos Aires, Georgetown');
189 $opt['-2'] = T('(GMT - 2:00) Mid-Atlantic, St. Helena');
190 $opt['-1'] = T('(GMT - 1:00) Azores, Cape Verde Islands');
191 $opt['0'] = T('(GMT) London, Dublin, Casablanca');
192 $opt['1'] = T('(GMT + 1:00) Berlin, Madrid, Paris');
193 $opt['2'] = T('(GMT + 2:00) Kaliningrad, South Africa, Warsaws');
194 $opt['3'] = T('(GMT + 3:00) Baghdad, Moscow, Nairobi');
195 $opt['3.5'] = T('(GMT + 3:30) Tehran');
196 $opt['4'] = T('(GMT + 4:00) Abu Dhabi, Tbilisi, Muscat');
197 $opt['4.5'] = T('(GMT + 4:30) Kabul');
198 $opt['5'] = T('(GMT + 5:00) Ekaterinburg, Islamabad, Tashkent');
199 $opt['5.5'] = T('(GMT + 5:30) Calcutta, Madras, New Delhi');
200 $opt['6'] = T('(GMT + 6:00) Almaty, Colomba, Dhakra');
201 $opt['7'] = T('(GMT + 7:00) Bangkok, Hanoi, Jakarta');
202 $opt['8'] = T('(GMT + 8:00) Beijing, Hong Kong, Singapore');
203 $opt['9'] = T('(GMT + 9:00) Seoul, Tokyo, Yakutsk');
204 $opt['9.5'] = T('(GMT + 9:30) Adelaide, Darwin');
205 $opt['10'] = T('(GMT + 10:00) Guam, Papua New Guinea, Sydney');
206 $opt['11'] = T('(GMT + 11:00) Magadan, New Caledonia, Solomon Islands');
207 $opt['12'] = T('(GMT + 12:00) Auckland, Wellington, Fiji');