Renaming classes to match file names
[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 $OBJECT = 'Date Formatting System';
30 $CLASS = 'Date_Formatter';
31 $OBJ = 'datef';
32
33 /**
34 * Defined constant time
35 */
36 define('TIMENOW', time());
37
38 /**
39 * Date Formatting System
40 *
41 * This framework handles the complexities of date and time formatting
42 * by taking variables like global timezone and user timezone, then
43 * adjusting timestamps accordingly.
44 *
45 * @author Iris Studios, Inc.
46 * @copyright Copyright ©2002 - [#]year[#], Iris Studios, Inc.
47 * @version $Revision$
48 * @package ISSO
49 *
50 */
51 class Date
52 {
53 /**
54 * Framework registry object
55 * @var object
56 */
57 var $registry = null;
58
59 /**
60 * User timezone offset
61 * @var integer
62 */
63 var $usertz = 0;
64
65 /**
66 * Server's timezone offset
67 * @var integer
68 */
69 var $servertz = 0;
70
71 /**
72 * Total offset timezone
73 * @var integer
74 */
75 var $offsettz = 0;
76
77 /**
78 * Offset in seconds
79 * @var integer
80 */
81 var $offset = 0;
82
83 /**
84 * Constructor: sets the server's timezone
85 */
86 function Date_Formatter(&$registry)
87 {
88 $this->registry =& $registry;
89
90 $this->servertz = date('Z', TIMENOW) / 3600;
91 }
92
93 /**
94 * Computes the total offset, taking into account all
95 * the various options
96 */
97 function fetch_offset()
98 {
99 $this->offsettz = $this->servertz - $this->usertz;
100 $this->offset = $this->offsettz * 3600;
101 }
102
103 /**
104 * Formats a UNIX timestamp to a certain date format in the proper time zone
105 *
106 * @param string Format of the date (same as PHP's date() function)
107 * @param integer UNIX timestamp to format
108 * @param bool Adjust the date to the user's language?
109 *
110 * @return string Formatted date
111 */
112 function format($format, $timestamp = TIMENOW, $adjust = true)
113 {
114 if ($adjust)
115 {
116 $timestamp -= $this->offset;
117 }
118
119 return date($format, $timestamp);
120 }
121
122 /**
123 * Fetches an array of timezones for a <select> list
124 *
125 * @return array List of timezones
126 */
127 function fetch_timezone_list()
128 {
129 $opt = array();
130
131 $opt['-12'] = '(GMT - 12:00) Enitwetok, Kwajalien';
132 $opt['-11'] = '(GMT - 11:00) Midway Island, Samoa';
133 $opt['-10'] = '(GMT - 10:00) Hawaii';
134 $opt['-9'] = '(GMT - 9:00) Alaska';
135 $opt['-8'] = '(GMT - 8:00) Pacific Time (US &amp; Canada)';
136 $opt['-7'] = '(GMT - 7:00) Mountain Time (US &amp; Canada)';
137 $opt['-6'] = '(GMT - 6:00) Central Time (US &amp; Canada)';
138 $opt['-5'] = '(GMT - 5:00) Eastern Time (US &amp; Canada)';
139 $opt['-4'] = '(GMT - 4:00) Atlantic Time (Canada)';
140 $opt['-3.5'] = '(GMT - 3:30) Newfoundland';
141 $opt['-3'] = '(GMT - 3:00) Brazil, Buenos Aires, Georgetown';
142 $opt['-2'] = '(GMT - 2:00) Mid-Atlantic, St. Helena';
143 $opt['-1'] = '(GMT - 1:00) Azores, Cape Verde Islands';
144 $opt['0'] = '(GMT) London, Dublin, Casablanca';
145 $opt['1'] = '(GMT + 1:00) Berlin, Madrid, Paris';
146 $opt['2'] = '(GMT + 2:00) Kaliningrad, South Africa, Warsaws';
147 $opt['3'] = '(GMT + 3:00) Baghdad, Moscow, Nairobi';
148 $opt['3.5'] = '(GMT + 3:30) Tehran';
149 $opt['4'] = '(GMT + 4:00) Abu Dhabi, Tbilisi, Muscat';
150 $opt['4.5'] = '(GMT + 4:30) Kabul';
151 $opt['5'] = '(GMT + 5:00) Ekaterinburg, Islamabad, Tashkent';
152 $opt['5.5'] = '(GMT + 5:30) Calcutta, Madras, New Delhi';
153 $opt['6'] = '(GMT + 6:00) Almaty, Colomba, Dhakra';
154 $opt['7'] = '(GMT + 7:00) Bangkok, Hanoi, Jakarta';
155 $opt['8'] = '(GMT + 8:00) Beijing, Hong Kong, Singapore';
156 $opt['9'] = '(GMT + 9:00) Seoul, Tokyo, Yakutsk';
157 $opt['9.5'] = '(GMT + 9:30) Adelaide, Darwin';
158 $opt['10'] = '(GMT + 10:00) Guam, Papua New Guinea, Sydney';
159 $opt['11'] = '(GMT + 11:00) Magadan, New Caledonia, Solomon Islands';
160 $opt['12'] = '(GMT + 12:00) Auckland, Wellington, Fiji';
161
162 return $opt;
163 }
164 }
165
166 /*=====================================================================*\
167 || ###################################################################
168 || # $HeadURL$
169 || # $Id$
170 || ###################################################################
171 \*=====================================================================*/
172 ?>