c3790433fd84befdb5370053fe6e8cd14bc878a3
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) {
23 // date couldn't be parsed
28 if (($gmt == 'Pacific') ||
($gmt == 'PST')) {
30 } else if (($gmt == 'EDT')) {
32 } else if (($gmt == 'Eastern') ||
($gmt == 'EST') ||
($gmt == 'CDT')) {
34 } else if (($gmt == 'Central') ||
($gmt == 'CST') ||
($gmt == 'MDT')) {
36 } else if (($gmt == 'Mountain') ||
($gmt == 'MST') ||
($gmt == 'PDT')) {
38 } else if ($gmt == 'BST') {
40 } else if ($gmt == 'EET') {
42 } else if ($gmt == 'GMT') {
44 } else if ($gmt == 'HKT') {
46 } else if ($gmt == 'IST') {
48 } else if ($gmt == 'JST') {
50 } else if ($gmt == 'KST') {
52 } else if ($gmt == 'MET') {
54 } else if ($gmt == 'MET DST' ||
$gmt == 'METDST') {
58 if (substr($gmt, 0, 1) == '-') {
60 $gmt = substr($gmt, 1, strlen($gmt));
61 } else if (substr($gmt, 0, 1) == '+') {
63 $gmt = substr($gmt, 1, strlen($gmt));
68 $difference = substr($gmt, 2, 2);
69 $gmt = substr($gmt, 0, 2);
70 $gmt = ($gmt +
($difference / 60)) * 3600;
77 /** now find what the server is at **/
78 $current = date('Z', time());
80 $current = - $current;
82 $stamp = (int)$stamp - (int)$gmt +
(int)$current;
88 Switch system has been intentionaly choosed for the
89 internationalization of month and day names. The reason
90 is to make sure that _("") strings will go into the
94 function getDayName( $day_number ) {
96 switch( $day_number ) {
107 $ret = _("Wednesday");
110 $ret = _("Thursday");
116 $ret = _("Saturday");
124 function getMonthName( $month_number ) {
125 switch( $month_number ) {
130 $ret = _("February");
151 $ret = _("September");
157 $ret = _("November");
160 $ret = _("December");
168 function date_intl( $date_format, $stamp ) {
170 $ret = str_replace( 'D', '$1', $date_format );
171 $ret = str_replace( 'F', '$2', $ret );
172 $ret = str_replace( 'l', '$4', $ret );
173 $ret = str_replace( 'M', '$5', $ret );
174 $ret = date( '$3'. $ret . '$3', $stamp ); // Workaround for a PHP 4.0.4 problem
175 $ret = str_replace( '$1', substr( getDayName( date( 'w', $stamp ) ), 0, 3 ), $ret );
176 $ret = str_replace( '$5', substr( getMonthName( date( 'm', $stamp ) ), 0, 3 ), $ret );
177 $ret = str_replace( '$2', getMonthName( date( 'm', $stamp ) ), $ret );
178 $ret = str_replace( '$4', getDayName( date( 'w', $stamp ) ), $ret );
179 $ret = str_replace( '$3', '', $ret );
184 function getLongDateString( $stamp ) {
192 if ( $hour_format == SMPREF_TIME_12HR
) {
193 $date_format = _("D, F j, Y g:i a");
195 $date_format = _("D, F j, Y G:i");
198 return( date_intl( $date_format, $stamp ) );
202 function getDateString( $stamp ) {
204 global $invert_time, $hour_format;
208 $dateZ = date('Z', $now );
212 $midnight = $now - ($now %
86400) - $dateZ;
214 if ($midnight < $stamp) {
216 if ( $hour_format == SMPREF_TIME_12HR
) {
217 $date_format = _("g:i a");
219 $date_format = _("G:i");
221 } else if ($midnight - 518400 < $stamp) {
223 if ( $hour_format == SMPREF_TIME_12HR
) {
224 $date_format = _("D, g:i a");
226 $date_format = _("D, G:i");
229 /* before this week */
230 $date_format = _("M j, Y");
233 return( date_intl( $date_format, $stamp ) );
236 function getTimeStamp($dateParts) {
237 /** $dateParts[0] == <day of week> Mon, Tue, Wed
238 ** $dateParts[1] == <day of month> 23
239 ** $dateParts[2] == <month> Jan, Feb, Mar
240 ** $dateParts[3] == <year> 1999
241 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS)
242 ** $dateParts[5] == <from GMT> +0100
243 ** $dateParts[6] == <zone> (EDT)
245 ** NOTE: In RFC 822, it states that <day of week> is optional.
246 ** In that case, dateParts[0] would be the <day of month>
247 ** and everything would be bumped up one.
251 * Simply check to see if the first element in the dateParts
252 * array is an integer or not.
253 * Since the day of week is optional, this check is needed.
255 * The old code used eregi('mon|tue|wed|thu|fri|sat|sun',
256 * $dateParts[0], $tmp) to find if the first element was the
257 * day of week or day of month. This is an expensive call
258 * (processing time) to have inside a loop. Doing it this way
259 * saves quite a bit of time for large mailboxes.
261 * It is also quicker to call explode only once rather than
262 * the 3 times it was getting called by calling the functions
263 * getHour, getMinute, and getSecond.
266 if (! isset($dateParts[1])) {
269 if (! isset($dateParts[2])) {
272 if (! isset($dateParts[3])) {
275 if (! isset($dateParts[4])) {
278 if (! isset($dateParts[5])) {
281 if (intval(trim($dateParts[0])) > 0) {
282 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
283 $dateParts[2] . ' ' . $dateParts[3];
284 return getGMTSeconds(strtotime($string), $dateParts[4]);
286 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' .
287 $dateParts[2] . ' ' . $dateParts[3] . ' ' . $dateParts[4];
288 if (isset($dateParts[5])) {
289 return getGMTSeconds(strtotime($string), $dateParts[5]);
291 return getGMTSeconds(strtotime($string), '');
295 /* I use this function for profiling. Should never be called in
296 actual versions of squirrelmail released to public. */
298 function getmicrotime() {
299 $mtime = microtime();
300 $mtime = explode(' ',$mtime);
301 $mtime = $mtime[1] + $mtime[0];