4ed0426a032d385a154fb94690e60f5212e63941
5 ** Copyright (c) 1999-2001 The Squirrelmail Development Team
6 ** Licensed under the GNU GPL. For full terms see the file COPYING.
8 ** Takes a date and parses it into a usable format. The form that a
9 ** date SHOULD arrive in is:
10 ** <Tue,> 29 Jun 1999 09:52:11 -0500 (EDT)
11 ** (as specified in RFC 822) -- 'Tue' is optional
16 // corrects a time stamp to be the local time
17 function getGMTSeconds($stamp, $gmt) {
19 if (($gmt == 'Pacific') ||
($gmt == 'PST'))
21 else if (($gmt == 'EDT'))
23 else if (($gmt == 'Eastern') ||
($gmt == 'EST') ||
($gmt == 'CDT'))
25 else if (($gmt == 'Central') ||
($gmt == 'CST') ||
($gmt == 'MDT'))
27 else if (($gmt == 'Mountain') ||
($gmt == 'MST') ||
($gmt == 'PDT'))
29 else if ($gmt == 'BST')
31 else if ($gmt == 'EET')
33 else if ($gmt == 'GMT')
35 else if ($gmt == 'HKT')
37 else if ($gmt == 'IST')
39 else if ($gmt == 'JST')
41 else if ($gmt == 'KST')
43 else if ($gmt == 'MET')
45 else if ($gmt == 'MET DST' ||
$gmt == 'METDST')
48 if (substr($gmt, 0, 1) == '-') {
50 $gmt = substr($gmt, 1, strlen($gmt));
51 } else if (substr($gmt, 0, 1) == '+') {
53 $gmt = substr($gmt, 1, strlen($gmt));
57 $gmt = substr($gmt, 0, 2);
64 /** now find what the server is at **/
65 $current = date('Z', time());
67 $current = - $current;
68 $stamp = (int)$stamp - (int)$gmt +
(int)$current;
74 Switch system has been intentionaly choosed for the
75 internationalization of month and day names. The reason
76 is to make sure that _("") strings will go into the
80 function getDayName( $day_number ) {
82 switch( $day_number ) {
93 $ret = _("Wednesday");
102 $ret = _("Saturday");
110 function getMonthName( $month_number ) {
111 switch( $month_number ) {
116 $ret = _("February");
137 $ret = _("September");
143 $ret = _("November");
146 $ret = _("December");
154 function date_intl( $date_format, $stamp ) {
156 $ret = str_replace( 'D', '$1', $date_format );
157 $ret = str_replace( 'F', '$2', $ret );
158 $ret = date( '$3'. $ret . '$3', $stamp ); // Workaround for a PHP 4.0.4 problem
159 $ret = str_replace( '$1', substr( getDayName( date( 'w', $stamp ) ), 0, 3 ), $ret );
160 $ret = str_replace( '$2', getMonthName( date( 'm', $stamp ) ), $ret );
161 $ret = str_replace( '$3', '', $ret );
166 function getLongDateString( $stamp ) {
168 return( date_intl( _("D, F j, Y g:i a"), $stamp ) );
172 function getDateString( $stamp ) {
178 $dateZ = date('Z', $now );
181 $midnight = $now - ($now %
86400) - $dateZ;
183 if ($midnight < $stamp) {
185 $date_format = _("g:i a");
186 } else if ($midnight - 518400 < $stamp) {
188 $date_format = _("D, g:i a");
191 $date_format = _("M j, Y");
194 return( date_intl( $date_format, $stamp ) );
195 // return( date( $date_i, $stamp ) );
198 function getTimeStamp($dateParts) {
199 /** $dateParts[0] == <day of week> Mon, Tue, Wed
200 ** $dateParts[1] == <day of month> 23
201 ** $dateParts[2] == <month> Jan, Feb, Mar
202 ** $dateParts[3] == <year> 1999
203 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
204 ** $dateParts[5] == <from GMT> +0100
205 ** $dateParts[6] == <zone> (EDT)
207 ** NOTE: In RFC 822, it states that <day of week> is optional.
208 ** In that case, dateParts[0] would be the <day of month>
209 ** and everything would be bumped up one.
212 // Simply check to see if the first element in the dateParts
213 // array is an integer or not.
214 // Since the day of week is optional, this check is needed.
216 // The old code used eregi('mon|tue|wed|thu|fri|sat|sun',
217 // $dateParts[0], $tmp) to find if the first element was the
218 // day of week or day of month. This is an expensive call
219 // (processing time) to have inside a loop. Doing it this way
220 // saves quite a bit of time for large mailboxes.
222 // It is also quicker to call explode only once rather than
223 // the 3 times it was getting called by calling the functions
224 // getHour, getMinute, and getSecond.
226 if (! isset($dateParts[1])) $dateParts[1] = '';
227 if (! isset($dateParts[2])) $dateParts[2] = '';
228 if (! isset($dateParts[3])) $dateParts[3] = '';
229 if (! isset($dateParts[4])) $dateParts[4] = '';
230 if (! isset($dateParts[5])) $dateParts[5] = '';
231 if (intval(trim($dateParts[0])) > 0) {
232 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
233 $dateParts[2] . ' ' . $dateParts[3];
234 return getGMTSeconds(strtotime($string), $dateParts[4]);
236 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
237 $dateParts[2] . ' ' . $dateParts[3] . ' ' . $dateParts[4];
238 if (isset($dateParts[5]))
239 return getGMTSeconds(strtotime($string), $dateParts[5]);
241 return getGMTSeconds(strtotime($string), '');
244 // I use this function for profiling. Should never be called in
245 // actual versions of squirrelmail released to public.
247 function getmicrotime() {
248 $mtime = microtime();
249 $mtime = explode(' ',$mtime);
250 $mtime = $mtime[1] + $mtime[0];