Advertisement
Search the Community
Showing results for tags 'time'.
-
Following functions are very useful to you but they haven't built-in right into IP.Board yet. So you gotta add them manually. Those two functions as follows... 1. timespan( $timespanToDate ) - Counts how much time between a pass date your specify through parameters and today. 2. daysleft( $toDate ) - Counts how much days left for a future date you specify through parameters. You can use these functions as an example to show how much days left to christmas and/or how much time spent since your board started! Open admin/sources/classes/class_localization.php and add following code right after getTimeOffset() function. (You're free to place wherever you like, but remember to add it outside of functions and inside the class) /** * Timespan to get years, months, days and etc between a specified date and the current timestamp * * @access public * @param string Date target * @return string */public function timespan( $timespanToDate ){ if( !is_int( $timespanToDate ) ) { $timespanToDate = strtotime( $timespanToDate ); } $diff = abs( time() - $timespanToDate ); $years = floor( $diff / ( 365 * 60 * 60 * 24 ) ); $months = floor( ( $diff - $years * 365 * 60 * 60 * 24 ) / ( 30 * 60 * 60 * 24 ) ); $days = floor( ( $diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 ) / ( 60 * 60 * 24 ) ); // $hours = floor( ( $diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24 ) / ( 60 * 60 ) ); // $minutes = floor( ( $diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24 - $hours * 60 * 60 ) / 60 ); // $seconds = floor( ( $diff - $years * 365 * 60 * 60 * 24 - $months * 30 * 60 * 60 * 24 - $days * 60 * 60 * 24 - $hours * 60 * 60 - $minutes * 60 ) ); $string = ""; if( $years AND $years >= 1 ) { $string .= $years. " years, "; } if( $months AND $months >= 1 ) { $string .= $months. " months and "; } if( $days AND $days >= 1 ) { $string .= $days. " days ago"; } return $string;}/** * Count how much days left from the current timestamp * * @access public * @param string Date target * @return integer */public function daysleft( $toDate ){ if( !is_int( $toDate ) ) { $toDate = strtotime( $toDate ); } $timeleftTime = $toDate - time(); $timeleftDays = round( ( ( $timeleftTime / 24 ) / 60 ) / 60 ); return $timeleftDays;} Indent the code once to keep the code structure intact. That's it! Enjoy using these in your board. Examples (PHP)... $this->registry->getClass('class_localization' )->timespan( '02 September 1993' );$this->registry->getClass('class_localization' )->daysleft( '05 April 2013' );