6 * Copyright (c) 1999-2002 The SquirrelMail Project 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 require_once( '../functions/constants.php' );
19 // corrects a time stamp to be the local time
20 function getGMTSeconds($stamp, $gmt) {
22 if (($gmt == 'Pacific') ||
($gmt == 'PST')) {
24 } else if (($gmt == 'EDT')) {
26 } else if (($gmt == 'Eastern') ||
($gmt == 'EST') ||
($gmt == 'CDT')) {
28 } else if (($gmt == 'Central') ||
($gmt == 'CST') ||
($gmt == 'MDT')) {
30 } else if (($gmt == 'Mountain') ||
($gmt == 'MST') ||
($gmt == 'PDT')) {
32 } else if ($gmt == 'BST') {
34 } else if ($gmt == 'EET') {
36 } else if ($gmt == 'GMT') {
38 } else if ($gmt == 'HKT') {
40 } else if ($gmt == 'IST') {
42 } else if ($gmt == 'JST') {
44 } else if ($gmt == 'KST') {
46 } else if ($gmt == 'MET') {
48 } else if ($gmt == 'MET DST' ||
$gmt == 'METDST') {
52 if (substr($gmt, 0, 1) == '-') {
54 $gmt = substr($gmt, 1, strlen($gmt));
55 } else if (substr($gmt, 0, 1) == '+') {
57 $gmt = substr($gmt, 1, strlen($gmt));
62 $gmt = substr($gmt, 0, 2);
70 /** now find what the server is at **/
71 $current = date('Z', time());
73 $current = - $current;
75 $stamp = (int)$stamp - (int)$gmt +
(int)$current;
81 Switch system has been intentionaly choosed for the
82 internationalization of month and day names. The reason
83 is to make sure that _("") strings will go into the
87 function getDayName( $day_number ) {
89 switch( $day_number ) {
100 $ret = _("Wednesday");
103 $ret = _("Thursday");
109 $ret = _("Saturday");
117 function getMonthName( $month_number ) {
118 switch( $month_number ) {
123 $ret = _("February");
144 $ret = _("September");
150 $ret = _("November");
153 $ret = _("December");
161 function date_intl( $date_format, $stamp ) {
163 $ret = str_replace( 'D', '$1', $date_format );
164 $ret = str_replace( 'F', '$2', $ret );
165 $ret = str_replace( 'l', '$4', $ret );
166 $ret = date( '$3'. $ret . '$3', $stamp ); // Workaround for a PHP 4.0.4 problem
167 $ret = str_replace( '$1', substr( getDayName( date( 'w', $stamp ) ), 0, 3 ), $ret );
168 $ret = str_replace( '$2', getMonthName( date( 'm', $stamp ) ), $ret );
169 $ret = str_replace( '$4', getDayName( date( 'w', $stamp ) ), $ret );
170 $ret = str_replace( '$3', '', $ret );
175 function getLongDateString( $stamp ) {
179 if ( $hour_format == SMPREF_TIME_12HR
) {
180 $date_format = _("D, F j, Y g:i a");
182 $date_format = _("D, F j, Y G:i");
185 return( date_intl( $date_format, $stamp ) );
189 function getDateString( $stamp ) {
191 global $invert_time, $hour_format;
195 $dateZ = date('Z', $now );
199 $midnight = $now - ($now %
86400) - $dateZ;
201 if ($midnight < $stamp) {
203 if ( $hour_format == SMPREF_TIME_12HR
) {
204 $date_format = _("g:i a");
206 $date_format = _("G:i");
208 } else if ($midnight - 518400 < $stamp) {
210 if ( $hour_format == SMPREF_TIME_12HR
) {
211 $date_format = _("D, g:i a");
213 $date_format = _("D, G:i");
216 /* before this week */
217 $date_format = _("M j, Y");
220 return( date_intl( $date_format, $stamp ) );
223 function getTimeStamp($dateParts) {
224 /** $dateParts[0] == <day of week> Mon, Tue, Wed
225 ** $dateParts[1] == <day of month> 23
226 ** $dateParts[2] == <month> Jan, Feb, Mar
227 ** $dateParts[3] == <year> 1999
228 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
229 ** $dateParts[5] == <from GMT> +0100
230 ** $dateParts[6] == <zone> (EDT)
232 ** NOTE: In RFC 822, it states that <day of week> is optional.
233 ** In that case, dateParts[0] would be the <day of month>
234 ** and everything would be bumped up one.
238 * Simply check to see if the first element in the dateParts
239 * array is an integer or not.
240 * Since the day of week is optional, this check is needed.
242 * The old code used eregi('mon|tue|wed|thu|fri|sat|sun',
243 * $dateParts[0], $tmp) to find if the first element was the
244 * day of week or day of month. This is an expensive call
245 * (processing time) to have inside a loop. Doing it this way
246 * saves quite a bit of time for large mailboxes.
248 * It is also quicker to call explode only once rather than
249 * the 3 times it was getting called by calling the functions
250 * getHour, getMinute, and getSecond.
253 if (! isset($dateParts[1])) {
256 if (! isset($dateParts[2])) {
259 if (! isset($dateParts[3])) {
262 if (! isset($dateParts[4])) {
265 if (! isset($dateParts[5])) {
268 if (intval(trim($dateParts[0])) > 0) {
269 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
270 $dateParts[2] . ' ' . $dateParts[3];
271 return getGMTSeconds(strtotime($string), $dateParts[4]);
273 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
274 $dateParts[2] . ' ' . $dateParts[3] . ' ' . $dateParts[4];
275 if (isset($dateParts[5])) {
276 return getGMTSeconds(strtotime($string), $dateParts[5]);
278 return getGMTSeconds(strtotime($string), '');
282 /* I use this function for profiling. Should never be called in
283 actual versions of squirrelmail released to public. */
285 function getmicrotime() {
286 $mtime = microtime();
287 $mtime = explode(' ',$mtime);
288 $mtime = $mtime[1] + $mtime[0];