Update version.php to 3.3.0
[isso.git] / Date.php
1 <?php
2 /*=====================================================================*\
3 || ###################################################################
4 || # Blue Static ISSO Framework
5 || # Copyright (c)2005-2009 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 2 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 (c)2005 - 2009, Blue Static
42 * @package ISSO
43 *
44 */
45 class BSDate
46 {
47 /**
48 * Offset in seconds; this is set using fetch_offset()
49 * @var integer
50 */
51 private $offset = 0;
52
53 /**
54 * Sets the user time zone and then calculates the total offset
55 *
56 * @param float User time zone
57 */
58 public function setUserTimeZone($usertz)
59 {
60 $this->offset = $usertz * 3600;
61 }
62
63 /**
64 * Formats a UNIX timestamp to a certain date format in the proper time
65 * zone
66 *
67 * @param string Format of the date (same as PHP's date() function)
68 * @param integer UNIX timestamp to format
69 * @param bool Adjust the date to the user's language?
70 *
71 * @return string Formatted date
72 */
73 public function format($format, $timestamp = TIMENOW, $adjust = true)
74 {
75 if ($adjust)
76 {
77 $timestamp += $this->offset;
78 }
79 return gmdate($format, $timestamp);
80 }
81
82 /**
83 * Fetches an array of timezone names indexed by their offset
84 *
85 * @return array List of timezones
86 */
87 public static function fetch_timezone_list()
88 {
89 $opt = array();
90
91 $opt['-12'] = _('(GMT - 12:00) Enitwetok, Kwajalien');
92 $opt['-11'] = _('(GMT - 11:00) Midway Island, Samoa');
93 $opt['-10'] = _('(GMT - 10:00) Hawaii');
94 $opt['-9'] = _('(GMT - 9:00) Alaska');
95 $opt['-8'] = _('(GMT - 8:00) Pacific Time (US &amp; Canada)');
96 $opt['-7'] = _('(GMT - 7:00) Mountain Time (US &amp; Canada)');
97 $opt['-6'] = _('(GMT - 6:00) Central Time (US &amp; Canada)');
98 $opt['-5'] = _('(GMT - 5:00) Eastern Time (US &amp; Canada)');
99 $opt['-4'] = _('(GMT - 4:00) Atlantic Time (Canada)');
100 $opt['-3.5'] = _('(GMT - 3:30) Newfoundland');
101 $opt['-3'] = _('(GMT - 3:00) Brazil, Buenos Aires, Georgetown');
102 $opt['-2'] = _('(GMT - 2:00) Mid-Atlantic, St. Helena');
103 $opt['-1'] = _('(GMT - 1:00) Azores, Cape Verde Islands');
104 $opt['0'] = _('(GMT) London, Dublin, Casablanca');
105 $opt['1'] = _('(GMT + 1:00) Berlin, Madrid, Paris');
106 $opt['2'] = _('(GMT + 2:00) Kaliningrad, South Africa, Warsaws');
107 $opt['3'] = _('(GMT + 3:00) Baghdad, Moscow, Nairobi');
108 $opt['3.5'] = _('(GMT + 3:30) Tehran');
109 $opt['4'] = _('(GMT + 4:00) Abu Dhabi, Tbilisi, Muscat');
110 $opt['4.5'] = _('(GMT + 4:30) Kabul');
111 $opt['5'] = _('(GMT + 5:00) Ekaterinburg, Islamabad, Tashkent');
112 $opt['5.5'] = _('(GMT + 5:30) Calcutta, Madras, New Delhi');
113 $opt['6'] = _('(GMT + 6:00) Almaty, Colomba, Dhakra');
114 $opt['7'] = _('(GMT + 7:00) Bangkok, Hanoi, Jakarta');
115 $opt['8'] = _('(GMT + 8:00) Beijing, Hong Kong, Singapore');
116 $opt['9'] = _('(GMT + 9:00) Seoul, Tokyo, Yakutsk');
117 $opt['9.5'] = _('(GMT + 9:30) Adelaide, Darwin');
118 $opt['10'] = _('(GMT + 10:00) Guam, Papua New Guinea, Sydney');
119 $opt['11'] = _('(GMT + 11:00) Magadan, New Caledonia, Solomon Islands');
120 $opt['12'] = _('(GMT + 12:00) Auckland, Wellington, Fiji');
121
122 return $opt;
123 }
124 }
125
126 ?>