Jump to content
WebFlake

2 new useful functions for your Class Localization!


Sandakelum

Recommended Posts

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' ); 
Edited by Sandakelum
  • Upvote 1
Link to comment
Share on other sites

If you own a license to IPB through an IPS purchase, I would not recommend removing that copyright. IPS does check up on these things, randomly. Just a piece of advice. I made the mistake of doing that and had to request IPS to add that copyright back in after I purchased my original license back in 2004.

Link to comment
Share on other sites

If you own a license to IPB through an IPS purchase, I would not recommend removing that copyright. IPS does check up on these things, randomly. Just a piece of advice. I made the mistake of doing that and had to request IPS to add that copyright back in after I purchased my original license back in 2004.

 

What you meant? I haven't removed any copyright from my community by the way, if you're talking about that. But I guess you posted that on the wrong topic... perhaps? 0_o

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...