[ Index ] |
|
Code source de e107 0.7.8 |
1 <?php 2 /* 3 + ----------------------------------------------------------------------------+ 4 | e107 website system 5 | 6 | ©Steve Dunstan 2001-2002 7 | http://e107.org 8 | jalist@e107.org 9 | 10 | Released under the terms and conditions of the 11 | GNU General Public License (http://gnu.org). 12 | 13 | $Source: /cvsroot/e107/e107_0.7/e107_handlers/date_handler.php,v $ 14 | $Revision: 1.10 $ 15 | $Date: 2007/01/17 20:46:54 $ 16 | $Author: e107steved $ 17 | 18 +----------------------------------------------------------------------------+ 19 */ 20 if (!defined('e107_INIT')) { exit; } 21 22 if (is_readable(e_LANGUAGEDIR.e_LANGUAGE."/lan_date.php")) { 23 @include_once(e_LANGUAGEDIR.e_LANGUAGE."/lan_date.php"); 24 } else { 25 @include_once(e_LANGUAGEDIR."English/lan_date.php"); 26 } 27 28 class convert 29 { 30 31 function convert_date($datestamp, $mode = "long") { 32 /* 33 # Date convert 34 # - parameter #1: string $datestamp, unix stamp 35 # - parameter #2: string $mode, date format, default long 36 # - return parsed text 37 # - scope public 38 */ 39 global $pref; 40 41 $datestamp += TIMEOFFSET; 42 43 if ($mode == "long") { 44 return strftime($pref['longdate'], $datestamp); 45 } else if ($mode == "short") { 46 return strftime($pref['shortdate'], $datestamp); 47 } else { 48 return strftime($pref['forumdate'], $datestamp); 49 } 50 } 51 52 function computeLapse($older_date, $newer_date = FALSE, $mode = FALSE, $show_secs = TRUE, $format = 'long') 53 { /* 54 $mode = TRUE :: return array 55 $mode = FALSE :: return string 56 */ 57 58 if($format == 'short') 59 { 60 $sec = LANDT_09; 61 $secs = LANDT_09s; 62 $min = LANDT_08; 63 $mins = LANDT_08s; 64 } 65 else 66 { 67 $sec = LANDT_07; 68 $secs = LANDT_07s; 69 $min = LANDT_06; 70 $mins = LANDT_06s; 71 } 72 /* 73 If we want an absolutely accurate result, main problems arise from the varying numbers of days in a month. 74 If we go over a month boundary, then we need to add days to end of start month, plus days in 'end' month 75 If start day > end day, we cross a month boundary. Calculate last day of start date. Otherwise we can just do a simple difference. 76 */ 77 $newer_date = ($newer_date == FALSE ? (time()) : $newer_date); 78 if($older_date>$newer_date) 79 { // Just in case the wrong way round 80 $tmp=$newer_date; 81 $newer_date=$older_date; 82 $older_date=$tmp; 83 } 84 $new_date = getdate($newer_date); 85 $old_date = getdate($older_date); 86 $result = array(); 87 $outputArray = array(); 88 89 $params = array( 90 6 => array('seconds',60, $sec, $secs), 91 5 => array('minutes',60, $min, $mins), 92 4 => array('hours',24, LANDT_05, LANDT_05s), 93 3 => array('mday', -1, LANDT_04, LANDT_04s), 94 2 => array('',-3, LANDT_03, LANDT_03s), 95 1 => array('mon',12, LANDT_02, LANDT_02s), 96 0 => array('year', -2, LANDT_01,LANDT_01s) 97 ); 98 99 $cy = 0; 100 foreach ($params as $parkey => $parval) 101 { 102 if ($parkey == 2) 103 { 104 $result['2'] = floor($result['3']/7); 105 $result['3'] = fmod($result['3'],7); 106 } 107 else 108 { 109 $tmp = $new_date[$parval[0]] - $old_date[$parval[0]] - $cy; 110 $scy = $cy; 111 $cy = 0; 112 if ($tmp < 0) 113 { 114 switch ($parval[1]) 115 { 116 case -1 : // Wrapround on months - special treatment 117 $tempdate = getdate(mktime(0,0,0,$old_date['mon']+1,1,$old_date['year']) - 1); // Last day of month 118 $tmp = $tempdate['mday'] - $old_date['mday'] + $new_date['mday'] - $scy; 119 $cy = 1; 120 break; 121 case -2 : // Year wraparound - shouldn't happen 122 case -3 : // Week processing - this shouldn't happen either 123 echo "Code bug!<br />"; 124 break; 125 default : 126 $cy = 1; 127 $tmp += $parval[1]; 128 } 129 } 130 $result[$parkey] = $tmp; 131 } 132 } 133 134 // Generate output array, add text 135 for ($i = 0; $i < ($show_secs ? 7 : 6); $i++) 136 { 137 $outputArray[] = $result[$i]." ".($result[$i] == 1 ? $params[$i][2] : $params[$i][3]); 138 } 139 return ($mode ? $outputArray : implode(", ", $outputArray)); 140 } 141 } 142 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Sun Apr 1 01:23:32 2007 | par Balluche grâce à PHPXref 0.7 |