[ Index ] |
|
Code source de phpMyVisites 2.3 |
1 <?php 2 /* 3 * phpMyVisites : website statistics and audience measurements 4 * Copyright (C) 2002 - 2006 5 * http://www.phpmyvisites.net/ 6 * phpMyVisites is free software (license GNU/GPL) 7 * Authors : phpMyVisites team 8 */ 9 10 // $Id: Date.class.php 29 2006-08-18 07:35:21Z matthieu_ $ 11 12 13 /** 14 * Class generic used for all date in the format YYYY-MM-DD 15 */ 16 class Date { 17 18 /** 19 * @var array 20 */ 21 var $info; 22 23 /** 24 * Constructor 25 * 26 * @param string $s_date 27 */ 28 function Date($s_date) 29 { 30 $s_date = $this->getValidDate($s_date); 31 $this->loadInfo($s_date); 32 } 33 34 function getValidDate($s_date) 35 { 36 if( strlen($s_date) === 10 37 && ($e = explode('-', $s_date)) 38 && sizeof($e) === 3 39 && strlen($e[0]) === 4 40 && is_numeric($e[0]) 41 && strlen($e[1]) === 2 42 && is_numeric($e[1]) 43 && strlen($e[2]) === 2 44 && is_numeric($e[2]) 45 ) 46 { 47 return $s_date; 48 } 49 else 50 { 51 return getDateFromTimestamp(time()); 52 } 53 } 54 55 function loadInfo($s_date) 56 { 57 $this->date = $s_date; 58 $this->info = $this->getInfo(); 59 } 60 /** 61 * returns date info array 62 * 63 * @access private 64 * @return array 65 */ 66 function getInfo() 67 { 68 $d = explode('-', $this->date); 69 $timestamp = mktime(23,59,59, $d[1], $d[2], $d[0]); 70 $week = date("W", $timestamp); 71 $weekDayNumber = date("w", $timestamp); 72 return array('year'=>$d[0], 'month'=>$d[1], 'day'=>$d[2], 'timestamp'=>$timestamp, 'week'=>$week, 73 'weekDayNumber'=>$weekDayNumber); 74 } 75 76 function setTimestamp($ts) 77 { 78 $this->loadInfo(getDateFromTimestamp($ts)); 79 } 80 81 function setDate($s_date) 82 { 83 $this->loadInfo($s_date); 84 } 85 86 function getWeekDayNumber() 87 { 88 return $this->info['weekDayNumber']; 89 } 90 91 /** 92 * returns date YYYY-MM-DD 93 * 94 * @return string 95 */ 96 function get() 97 { 98 return $this->info['year']."-".$this->info['month']."-".$this->info['day']; 99 } 100 101 /** 102 * returns timestamp 103 * 104 * @return string 105 */ 106 function getTimestamp() 107 { 108 return $this->info['timestamp']; 109 } 110 111 /** 112 * returns day 113 * 114 * @return string 115 */ 116 function getDay() 117 { 118 return $this->info['day']; 119 } 120 121 /** 122 * returns month 123 * 124 * @return string 125 */ 126 function getMonth() 127 { 128 return $this->info['month']; 129 } 130 131 /** 132 * returns year 133 * 134 * @return string 135 */ 136 function getYear() 137 { 138 return $this->info['year']; 139 } 140 141 /** 142 * returns ISO-8601 week number of year, weeks starting on Monday 143 * 144 * @return string 145 */ 146 function getWeek() 147 { 148 return $this->info['week']; 149 } 150 151 /** 152 * returns true if the period of the object calling this method is finished 153 * 154 * @param int $period 155 * 156 * @return bool 157 */ 158 function isPeriodFinished($period) 159 { 160 if($period === DB_ARCHIVES_PERIOD_DAY) 161 { 162 return $this->isDayFinished(); 163 } 164 else if($period === DB_ARCHIVES_PERIOD_MONTH) 165 { 166 return $this->isMonthFinished(); 167 } 168 else 169 { 170 print("Period asked in isPeriodFinished UNKNOWN<br>"); 171 return true; 172 } 173 } 174 175 /** 176 * returns true if day of period is older than today 177 * 178 * @access private 179 * @return bool 180 */ 181 function isDayFinished() 182 { 183 if($this->getTimestamp() < time()) 184 { 185 return true; 186 } 187 else 188 { 189 return false; 190 } 191 } 192 193 /** 194 * returns true if month of period is older than current month 195 * 196 * @access private 197 * @return bool 198 */ 199 function isMonthFinished() 200 { 201 if($this->getYear() == date("Y") && $this->getMonth() >= date("m")) 202 { 203 return false; 204 } 205 else 206 { 207 return true; 208 } 209 } 210 /** 211 * Adds x days to date 212 * Works with daylight saving time 213 */ 214 function addDays($nbDaysToAdd) 215 { 216 $this->setTimestamp(mktime(23, 59, 59, $this->info['month'] , $this->info['day'] + $nbDaysToAdd, $this->info['year'])); 217 } 218 } 219 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 14:10:01 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |