00001 <?php
00002
00003
00004 lt_include( PLOG_CLASS_PATH."class/config/config.class.php" );
00005 lt_include( PLOG_CLASS_PATH."class/locale/locales.class.php" );
00006 lt_include( PLOG_CLASS_PATH."class/data/Date.class.php" );
00007
00013 define( "TIME_DIFFERENCE_CALCULATION_DYNAMIC", 0 );
00014 define( "TIME_DIFFERENCE_CALCULATION_STATIC", 1 );
00015
00016
00041 class Timestamp extends Date
00042 {
00043
00044
00045
00046
00047
00048
00049
00050 function Timestamp( $timestamp = null )
00051 {
00052
00053 $this->Date( $timestamp );
00054 }
00055
00059 function setTime( $timestamp, $format = DATE_FORMAT_ISO )
00060 {
00061 $this->setDate( $timestamp, $format );
00062 }
00063
00067 function getTimestamp( $format = DATE_FORMAT_TIMESTAMP )
00068 {
00069 return $this->getDate( $format );
00070 }
00071
00072
00080 function getCentury()
00081 {
00082
00083 throw( new Exception("not implemented?"));
00084 die();
00085 }
00086
00092 function getMinutes()
00093 {
00094 return $this->getMinute();
00095 }
00096
00102 function getSeconds()
00103 {
00104 return $this->getSecond();
00105 }
00106
00112 function getMonthString()
00113 {
00114 throw( new Exception("Timestamp::getMonthString not implemented. Use Locale::formatDate instead!"));
00115 die();
00116 }
00117
00121 function getMonth()
00122 {
00123
00124 $month = Date::getMonth();
00125 if( $month < 10 && $month[0] != "0" )
00126 $month = "0".$month;
00127
00128 return $month;
00129 }
00130
00136 function setMinutes( $newMinutes )
00137 {
00138 $this->setMinute( $newMinutes );
00139 }
00140
00147 function getWeekdayId()
00148 {
00149 return $this->getDayOfWeek();
00150 }
00151
00155 function getNextMonthAndYear()
00156 {
00157 if( $this->_month == 12 ) {
00158 $month = "01";
00159 $year = $this->_year+1;
00160 }
00161 else {
00162 $month = $this->_month+1;
00163 if( $month < 10 )
00164 $month = "0".$month;
00165 $year = $this->_year;
00166 }
00167
00168 return $year.$month;
00169 }
00170
00174 function setNextMonthAndYear()
00175 {
00176 $result = $this->getNextMonthAndYear();
00177
00178 $this->setYear( substr( $result, 0, 4 ));
00179 $this->setMonth( substr( $result, 4, 2 ));
00180
00181 $this->_calculateFields();
00182 }
00183
00187 function getPrevMonthAndYear()
00188 {
00189 if( $this->_month == 01 ) {
00190 $month = 12;
00191 $year = $this->_year-1;
00192 }
00193 else {
00194 $month = $this->_month - 1;
00195 if( $month < 10 )
00196 $month = "0".$month;
00197 $year = $this->_year;
00198 }
00199
00200 return $year.$month;
00201 }
00202
00206 function setPrevMonthAndYear()
00207 {
00208 $result = $this->getPrevMonthAndYear();
00209
00210 $this->setYear( substr( $result, 0, 4 ));
00211 $this->setMonth( substr( $result, 4, 2 ));
00212
00213 $this->_calculateFields();
00214 }
00215
00221 function getUnixDate()
00222 {
00223 return $this->getDate( DATE_FORMAT_UNIXTIME );
00224 }
00225
00231 function getIsoDate()
00232 {
00233 return $this->getDate( DATE_FORMAT_ISO );
00234 }
00235
00240 function getW3Date()
00241 {
00242 return $this->getDate( DATE_FORMAT_ISO_EXTENDED );
00243 }
00244
00254 function getDateWithOffset( $timeStamp, $timeDiff )
00255 {
00256 if( $timeDiff != 0 ) {
00257 $t = new Timestamp( $timeStamp );
00258
00259
00260
00261
00262
00263 if( $timeDiff > 0 )
00264 $t->addSeconds( $timeDiff * 3600 );
00265 else
00266 $t->subtractSeconds( $timeDiff * (-3600));
00267
00268 $date = $t->getTimestamp();
00269 }
00270 else {
00271 $date = $timeStamp;
00272 }
00273
00274 return $date;
00275 }
00276
00287 function getTimestampWithOffset( $timeStamp, $timeDiff )
00288 {
00289 return( new Timestamp( Timestamp::getDateWithOffset( $timeStamp, $timeDiff )));
00290 }
00291
00302 function getBlogDate( $blog, $timestamp = null )
00303 {
00304
00305
00306
00307 $config =& Config::getConfig();
00308 if( $config->getValue( "time_difference_calculation" ) == TIME_DIFFERENCE_CALCULATION_DYNAMIC )
00309 return( new Timestamp( $timestamp ));
00310
00311
00312
00313
00314
00315
00316
00317 if( is_object( $blog )) {
00318 $blogSettings = $blog->getSettings();
00319 $timeDifference = $blogSettings->getValue( "time_offset" );
00320 }
00321 else {
00322 lt_include( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
00323 $blogs = new Blogs();
00324 $blogInfo = $blogs->getBlogInfoById( $blog );
00325 if( !$blogInfo )
00326 $timeDifference = 0;
00327 else {
00328 $blogSettings = $blogInfo->getSettings();
00329 $timeDifference = $blogSettings->getValue( "time_offset" );
00330 }
00331 }
00332
00333
00334 $t = new Timestamp();
00335 $t->setDate( Timestamp::getDateWithOffset( $t->getDate(), $timeDifference ), DATE_FORMAT_TIMESTAMP );
00336
00337 return $t;
00338 }
00339
00345 function getAllHours()
00346 {
00347 $hours = Array( "00", "01", "02", "03", "04", "05", "06", "07", "08",
00348 "09", "10", "11", "12", "13", "14", "15", "16", "17",
00349 "18", "19", "20", "21", "22", "23" );
00350
00351 return $hours;
00352 }
00353
00359 function getAllMinutes()
00360 {
00361 $minutes = Array( "00", "01", "02", "03", "04", "05", "06", "07", "08", "09",
00362 "10", "11", "12", "13", "14", "15", "16", "17", "18", "19",
00363 "20", "21", "22", "23", "24", "25", "26", "27", "28", "29",
00364 "30", "31", "32", "33", "34", "35", "36", "37", "38", "39",
00365 "40", "41", "42", "43", "44", "45", "46", "47", "48", "49",
00366 "50", "51", "52", "53", "54", "55", "56", "57", "58", "59" );
00367
00368 return $minutes;
00369 }
00370
00376 function getNowTimestamp()
00377 {
00378 $t = new Timestamp();
00379 return( $t->getTimestamp());
00380 }
00381
00387 function getYears( $minYear = 1900, $maxYear = 2099 )
00388 {
00389 return( range( $minYear, $maxYear ));
00390 }
00391
00401 function parseDate( $dateString )
00402 {
00403
00404 $timestamp = strtotime( $dateString );
00405
00406
00407 $date = new Timestamp( $timestamp );
00408
00409
00410 return( $date );
00411 }
00412 }
00413 ?>