[ Index ] |
|
Code source de eGroupWare 1.2.106-2 |
1 <?php 2 /** 3 ** date.php 4 ** 5 ** Takes a date and parses it into a usable format. The form that a 6 ** date SHOULD arrive in is: 7 ** <Tue,> 29 Jun 1999 09:52:11 -0500 (EDT) 8 ** (as specified in RFC 822) -- 'Tue' is optional 9 ** 10 ** $Id: class.transformdate.inc.php 18876 2005-07-23 15:52:49Z ralfbecker $ 11 **/ 12 13 class transformdate 14 { 15 16 // corrects a time stamp to be the local time 17 function getGMTSeconds($stamp, $gmt) 18 { 19 global $invert_time; 20 21 if (($gmt == 'Pacific') || ($gmt == 'PST')) 22 $gmt = '-0800'; 23 else if (($gmt == 'EDT')) 24 $gmt = '-0400'; 25 else if (($gmt == 'Eastern') || ($gmt == 'EST') || ($gmt == 'CDT')) 26 $gmt = '-0500'; 27 else if (($gmt == 'Central') || ($gmt == 'CST') || ($gmt == 'MDT')) 28 $gmt = '-0600'; 29 else if (($gmt == 'Mountain') || ($gmt == 'MST') || ($gmt == 'PDT')) 30 $gmt = '-0700'; 31 else if ($gmt == 'BST') 32 $gmt = '+0100'; 33 else if ($gmt == 'EET') 34 $gmt = '+0200'; 35 else if ($gmt == 'GMT') 36 $gmt = '+0000'; 37 else if ($gmt == 'HKT') 38 $gmt = '+0800'; 39 else if ($gmt == 'IST') 40 $gmt = '+0200'; 41 else if ($gmt == 'JST') 42 $gmt = '+0900'; 43 else if ($gmt == 'MET') 44 $gmt = '+0100'; 45 else if ($gmt == 'MET DST' || $gmt == 'METDST') 46 $gmt = '+0200'; 47 48 if (substr($gmt, 0, 1) == '-') 49 { 50 $neg = true; 51 $gmt = substr($gmt, 1, strlen($gmt)); 52 } 53 else if (substr($gmt, 0, 1) == '+') 54 { 55 $neg = false; 56 $gmt = substr($gmt, 1, strlen($gmt)); 57 } 58 else 59 $neg = false; 60 61 $gmt = substr($gmt, 0, 2); 62 $gmt = $gmt * 3600; 63 if ($neg == true) 64 $gmt = "-$gmt"; 65 else 66 $gmt = "+$gmt"; 67 68 /** now find what the server is at **/ 69 $current = date('Z', time()); 70 if ($invert_time) 71 $current = - $current; 72 $stamp = (int)$stamp - (int)$gmt + (int)$current; 73 74 return $stamp; 75 } 76 77 function getLongDateString($stamp) 78 { 79 return date('D, F j, Y g:i a', $stamp); 80 } 81 82 function getDateString($stamp) 83 { 84 85 global $invert_time; 86 87 $now = time(); 88 $dateZ = date('Z', $now); 89 if ($invert_time) 90 $dateZ = - $dateZ; 91 $midnight = $now - ($now % 86400) - $dateZ; 92 93 if ($midnight < $stamp) 94 { 95 // Today 96 return date('g:i a', $stamp); 97 } 98 else if ($midnight - (60 * 60 * 24 * 6) < $stamp) 99 { 100 // This week 101 return date('D, g:i a', $stamp); 102 } 103 else 104 { 105 // before this week 106 return date('M j, Y', $stamp); 107 } 108 } 109 110 function getTimeStamp($dateParts) 111 { 112 /** $dateParts[0] == <day of week> Mon, Tue, Wed 113 ** $dateParts[1] == <day of month> 23 114 ** $dateParts[2] == <month> Jan, Feb, Mar 115 ** $dateParts[3] == <year> 1999 116 ** $dateParts[4] == <time> 18:54:23 (HH:MM:SS) 117 ** $dateParts[5] == <from GMT> +0100 118 ** $dateParts[6] == <zone> (EDT) 119 ** 120 ** NOTE: In RFC 822, it states that <day of week> is optional. 121 ** In that case, dateParts[0] would be the <day of month> 122 ** and everything would be bumped up one. 123 **/ 124 125 // Simply check to see if the first element in the dateParts 126 // array is an integer or not. 127 // Since the day of week is optional, this check is needed. 128 // 129 // The old code used eregi('mon|tue|wed|thu|fri|sat|sun', 130 // $dateParts[0], $tmp) to find if the first element was the 131 // day of week or day of month. This is an expensive call 132 // (processing time) to have inside a loop. Doing it this way 133 // saves quite a bit of time for large mailboxes. 134 // 135 // It is also quicker to call explode only once rather than 136 // the 3 times it was getting called by calling the functions 137 // getHour, getMinute, and getSecond. 138 // 139 if (intval(trim($dateParts[0])) > 0) 140 { 141 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' . 142 $dateParts[2] . ' ' . $dateParts[3]; 143 return $this->getGMTSeconds(strtotime($string), $dateParts[4]); 144 } 145 $string = $dateParts[0] . ' ' . $dateParts[1] . ' ' . 146 $dateParts[2] . ' ' . $dateParts[3] . ' ' . $dateParts[4]; 147 if (isset($dateParts[5])) 148 return $this->getGMTSeconds(strtotime($string), $dateParts[5]); 149 else 150 return $this->getGMTSeconds(strtotime($string), ''); 151 } 152 153 // I use this function for profiling. Should never be called in 154 // actual versions of felamimail released to public. 155 function getmicrotime() 156 { 157 $mtime = microtime(); 158 $mtime = explode(' ',$mtime); 159 $mtime = $mtime[1] + $mtime[0]; 160 return ($mtime); 161 } 162 } 163 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Feb 25 17:20:01 2007 | par Balluche grâce à PHPXref 0.7 |