6 * Copyright (c) 1999-2001 The SquirrelMail Development Team
7 * Licensed under the GNU GPL. For full terms see the file COPYING.
9 * Takes a date and parses it into a usable format. The form that a
10 * date SHOULD arrive in is:
11 * <Tue,> 29 Jun 1999 09:52:11 -0500 (EDT)
12 * (as specified in RFC 822) -- 'Tue' is optional
17 /*****************************************************************/
18 /*** THIS FILE NEEDS TO HAVE ITS FORMATTING FIXED!!! ***/
19 /*** PLEASE DO SO AND REMOVE THIS COMMENT SECTION. ***/
20 /*** + Base level indent should begin at left margin, as ***/
21 /*** the first line of the function definition below. ***/
22 /*** + All identation should consist of four space blocks ***/
23 /*** + Tab characters are evil. ***/
24 /*** + all comments should use "slash-star ... star-slash" ***/
25 /*** style -- no pound characters, no slash-slash style ***/
26 /*** + FLOW CONTROL STATEMENTS (if, while, etc) SHOULD ***/
27 /*** ALWAYS USE { AND } CHARACTERS!!! ***/
28 /*** + Please use ' instead of ", when possible. Note " ***/
29 /*** should always be used in _( ) function calls. ***/
30 /*** Thank you for your help making the SM code more readable. ***/
31 /*****************************************************************/
33 // corrects a time stamp to be the local time
34 function getGMTSeconds($stamp, $gmt) {
36 if (($gmt == 'Pacific') ||
($gmt == 'PST'))
38 else if (($gmt == 'EDT'))
40 else if (($gmt == 'Eastern') ||
($gmt == 'EST') ||
($gmt == 'CDT'))
42 else if (($gmt == 'Central') ||
($gmt == 'CST') ||
($gmt == 'MDT'))
44 else if (($gmt == 'Mountain') ||
($gmt == 'MST') ||
($gmt == 'PDT'))
46 else if ($gmt == 'BST')
48 else if ($gmt == 'EET')
50 else if ($gmt == 'GMT')
52 else if ($gmt == 'HKT')
54 else if ($gmt == 'IST')
56 else if ($gmt == 'JST')
58 else if ($gmt == 'KST')
60 else if ($gmt == 'MET')
62 else if ($gmt == 'MET DST' ||
$gmt == 'METDST')
65 if (substr($gmt, 0, 1) == '-') {
67 $gmt = substr($gmt, 1, strlen($gmt));
68 } else if (substr($gmt, 0, 1) == '+') {
70 $gmt = substr($gmt, 1, strlen($gmt));
74 $gmt = substr($gmt, 0, 2);
81 /** now find what the server is at **/
82 $current = date('Z', time());
84 $current = - $current;
85 $stamp = (int)$stamp - (int)$gmt +
(int)$current;
91 Switch system has been intentionaly choosed for the
92 internationalization of month and day names. The reason
93 is to make sure that _("") strings will go into the
97 function getDayName( $day_number ) {
99 switch( $day_number ) {
110 $ret = _("Wednesday");
113 $ret = _("Thursday");
119 $ret = _("Saturday");
127 function getMonthName( $month_number ) {
128 switch( $month_number ) {
133 $ret = _("February");
154 $ret = _("September");
160 $ret = _("November");
163 $ret = _("December");
171 function date_intl( $date_format, $stamp ) {
173 $ret = str_replace( 'D', '$1', $date_format );
174 $ret = str_replace( 'F', '$2', $ret );
175 $ret = date( '$3'. $ret . '$3', $stamp ); // Workaround for a PHP 4.0.4 problem
176 $ret = str_replace( '$1', substr( getDayName( date( 'w', $stamp ) ), 0, 3 ), $ret );
177 $ret = str_replace( '$2', getMonthName( date( 'm', $stamp ) ), $ret );
178 $ret = str_replace( '$3', '', $ret );
183 function getLongDateString( $stamp ) {
185 return( date_intl( _("D, F j, Y g:i a"), $stamp ) );
189 function getDateString( $stamp ) {
195 $dateZ = date('Z', $now );
198 $midnight = $now - ($now %
86400) - $dateZ;
200 if ($midnight < $stamp) {
202 $date_format = _("g:i a");
203 } else if ($midnight - 518400 < $stamp) {
205 $date_format = _("D, g:i a");
208 $date_format = _("M j, Y");
211 return( date_intl( $date_format, $stamp ) );
212 // return( date( $date_i, $stamp ) );
215 function getTimeStamp($dateParts) {
216 /** $dateParts[0] == <day of week> Mon, Tue, Wed
217 ** $dateParts[1] == <day of month> 23
218 ** $dateParts[2] == <month> Jan, Feb, Mar
219 ** $dateParts[3] == <year> 1999
220 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
221 ** $dateParts[5] == <from GMT> +0100
222 ** $dateParts[6] == <zone> (EDT)
224 ** NOTE: In RFC 822, it states that <day of week> is optional.
225 ** In that case, dateParts[0] would be the <day of month>
226 ** and everything would be bumped up one.
229 // Simply check to see if the first element in the dateParts
230 // array is an integer or not.
231 // Since the day of week is optional, this check is needed.
233 // The old code used eregi('mon|tue|wed|thu|fri|sat|sun',
234 // $dateParts[0], $tmp) to find if the first element was the
235 // day of week or day of month. This is an expensive call
236 // (processing time) to have inside a loop. Doing it this way
237 // saves quite a bit of time for large mailboxes.
239 // It is also quicker to call explode only once rather than
240 // the 3 times it was getting called by calling the functions
241 // getHour, getMinute, and getSecond.
243 if (! isset($dateParts[1])) $dateParts[1] = '';
244 if (! isset($dateParts[2])) $dateParts[2] = '';
245 if (! isset($dateParts[3])) $dateParts[3] = '';
246 if (! isset($dateParts[4])) $dateParts[4] = '';
247 if (! isset($dateParts[5])) $dateParts[5] = '';
248 if (intval(trim($dateParts[0])) > 0) {
249 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
250 $dateParts[2] . ' ' . $dateParts[3];
251 return getGMTSeconds(strtotime($string), $dateParts[4]);
253 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
254 $dateParts[2] . ' ' . $dateParts[3] . ' ' . $dateParts[4];
255 if (isset($dateParts[5]))
256 return getGMTSeconds(strtotime($string), $dateParts[5]);
258 return getGMTSeconds(strtotime($string), '');
261 // I use this function for profiling. Should never be called in
262 // actual versions of squirrelmail released to public.
264 function getmicrotime() {
265 $mtime = microtime();
266 $mtime = explode(' ',$mtime);
267 $mtime = $mtime[1] + $mtime[0];