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