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